diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:15:05 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:15:05 +0000 |
commit | 46651ce6fe013220ed397add242004d764fc0153 (patch) | |
tree | 6e5299f990f88e60174a1d3ae6e48eedd2688b2b /src/interfaces/ecpg/test/sql/func.pgc | |
parent | Initial commit. (diff) | |
download | postgresql-14-upstream.tar.xz postgresql-14-upstream.zip |
Adding upstream version 14.5.upstream/14.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/interfaces/ecpg/test/sql/func.pgc')
-rw-r--r-- | src/interfaces/ecpg/test/sql/func.pgc | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/test/sql/func.pgc b/src/interfaces/ecpg/test/sql/func.pgc new file mode 100644 index 0000000..5ebcafa --- /dev/null +++ b/src/interfaces/ecpg/test/sql/func.pgc @@ -0,0 +1,47 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +EXEC SQL INCLUDE ../regression; + +int main() { + EXEC SQL char text[25]; + + ECPGdebug(1, stderr); + EXEC SQL CONNECT TO REGRESSDB1; + + EXEC SQL SET AUTOCOMMIT TO ON; + EXEC SQL WHENEVER SQLWARNING SQLPRINT; + EXEC SQL WHENEVER SQLERROR SQLPRINT; + + EXEC SQL CREATE TABLE My_Table ( Item1 int, Item2 text ); + EXEC SQL CREATE TABLE Log (name text, w text); + + EXEC SQL CREATE FUNCTION My_Table_Check() RETURNS trigger + AS $test$ + BEGIN + INSERT INTO Log VALUES(TG_NAME, TG_WHEN); + RETURN NEW; + END; $test$ + LANGUAGE plpgsql; + + EXEC SQL CREATE TRIGGER My_Table_Check_Trigger + BEFORE INSERT + ON My_Table + FOR EACH ROW + EXECUTE PROCEDURE My_Table_Check(); + + EXEC SQL INSERT INTO My_Table VALUES (1234, 'Some random text'); + EXEC SQL INSERT INTO My_Table VALUES (5678, 'The Quick Brown'); + EXEC SQL SELECT name INTO :text FROM Log LIMIT 1; + printf("Trigger %s fired.\n", text); + + EXEC SQL DROP TRIGGER My_Table_Check_Trigger ON My_Table; + EXEC SQL DROP FUNCTION My_Table_Check(); + EXEC SQL DROP TABLE Log; + EXEC SQL DROP TABLE My_Table; + + EXEC SQL DISCONNECT ALL; + + return 0; +} |