File: test.sql

package info (click to toggle)
postgresql-plsh 1.3-3.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,364 kB
  • ctags: 39
  • sloc: sh: 8,849; ansic: 420; makefile: 62; sql: 30
file content (40 lines) | stat: -rw-r--r-- 867 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
\set ECHO all
DROP SCHEMA plsh_test CASCADE;
CREATE SCHEMA plsh_test;
SET search_path TO plsh_test;

CREATE FUNCTION valtest(text) RETURNS text AS 'foo' LANGUAGE plsh;

CREATE FUNCTION shtest (text, text) RETURNS text AS '
#!/bin/sh
echo "One: $1 Two: $2"
if test $1 = $2; then
    echo ''this is an error'' 1>&2
fi
exit 0
' LANGUAGE plsh;

SELECT shtest('foo', 'bar');
SELECT shtest('xxx', 'xxx');

CREATE FUNCTION shtrigger() RETURNS trigger AS '
#!/bin/sh
(
for arg do
    echo "Arg is $arg"
done
) >> $HOME/voodoo-pgplsh-test
exit 0
' LANGUAGE plsh;

CREATE TABLE pfoo (a int, b text);

CREATE TRIGGER testtrigger AFTER INSERT ON pfoo
    FOR EACH ROW EXECUTE PROCEDURE shtrigger('dummy');

INSERT INTO pfoo VALUES (1, 'one');
INSERT INTO pfoo VALUES (2, 'two');
INSERT INTO pfoo VALUES (3, 'three');

\!cat $HOME/voodoo-pgplsh-test
\!rm $HOME/voodoo-pgplsh-test