Commit 0c1f8f16 authored by Peter Eisentraut's avatar Peter Eisentraut

Use EXECUTE FUNCTION syntax for triggers more

Change pg_dump and ruleutils.c to use the FUNCTION keyword instead of
PROCEDURE in trigger and event trigger definitions.

This completes the pieces of the transition started in
0a63f996 that were kept out of
PostgreSQL 11 because of the required catversion change.

Discussion: https://www.postgresql.org/message-id/381bef53-f7be-29c8-d977-948e389161d6@2ndquadrant.com
parent 13b89f96
...@@ -2094,12 +2094,12 @@ CREATE VIEW triggers AS ...@@ -2094,12 +2094,12 @@ CREATE VIEW triggers AS
AS cardinal_number) AS action_order, AS cardinal_number) AS action_order,
CAST( CAST(
CASE WHEN pg_has_role(c.relowner, 'USAGE') CASE WHEN pg_has_role(c.relowner, 'USAGE')
THEN (regexp_match(pg_get_triggerdef(t.oid), E'.{35,} WHEN \\((.+)\\) EXECUTE PROCEDURE'))[1] THEN (regexp_match(pg_get_triggerdef(t.oid), E'.{35,} WHEN \\((.+)\\) EXECUTE FUNCTION'))[1]
ELSE null END ELSE null END
AS character_data) AS action_condition, AS character_data) AS action_condition,
CAST( CAST(
substring(pg_get_triggerdef(t.oid) from substring(pg_get_triggerdef(t.oid) from
position('EXECUTE PROCEDURE' in substring(pg_get_triggerdef(t.oid) from 48)) + 47) position('EXECUTE FUNCTION' in substring(pg_get_triggerdef(t.oid) from 48)) + 47)
AS character_data) AS action_statement, AS character_data) AS action_statement,
CAST( CAST(
-- hard-wired reference to TRIGGER_TYPE_ROW -- hard-wired reference to TRIGGER_TYPE_ROW
......
...@@ -1044,7 +1044,7 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty) ...@@ -1044,7 +1044,7 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty)
appendStringInfoString(&buf, ") "); appendStringInfoString(&buf, ") ");
} }
appendStringInfo(&buf, "EXECUTE PROCEDURE %s(", appendStringInfo(&buf, "EXECUTE FUNCTION %s(",
generate_function_name(trigrec->tgfoid, 0, generate_function_name(trigrec->tgfoid, 0,
NIL, argtypes, NIL, argtypes,
false, NULL, EXPR_KIND_NONE)); false, NULL, EXPR_KIND_NONE));
......
...@@ -17086,7 +17086,7 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) ...@@ -17086,7 +17086,7 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
appendPQExpBufferStr(query, " FOR EACH STATEMENT\n "); appendPQExpBufferStr(query, " FOR EACH STATEMENT\n ");
/* regproc output is already sufficiently quoted */ /* regproc output is already sufficiently quoted */
appendPQExpBuffer(query, "EXECUTE PROCEDURE %s(", appendPQExpBuffer(query, "EXECUTE FUNCTION %s(",
tginfo->tgfname); tginfo->tgfname);
tgargs = (char *) PQunescapeBytea((unsigned char *) tginfo->tgargs, tgargs = (char *) PQunescapeBytea((unsigned char *) tginfo->tgargs,
...@@ -17200,7 +17200,7 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo) ...@@ -17200,7 +17200,7 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo)
appendPQExpBufferChar(query, ')'); appendPQExpBufferChar(query, ')');
} }
appendPQExpBufferStr(query, "\n EXECUTE PROCEDURE "); appendPQExpBufferStr(query, "\n EXECUTE FUNCTION ");
appendPQExpBufferStr(query, evtinfo->evtfname); appendPQExpBufferStr(query, evtinfo->evtfname);
appendPQExpBufferStr(query, "();\n"); appendPQExpBufferStr(query, "();\n");
......
...@@ -1540,11 +1540,11 @@ my %tests = ( ...@@ -1540,11 +1540,11 @@ my %tests = (
create_order => 33, create_order => 33,
create_sql => 'CREATE EVENT TRIGGER test_event_trigger create_sql => 'CREATE EVENT TRIGGER test_event_trigger
ON ddl_command_start ON ddl_command_start
EXECUTE PROCEDURE dump_test.event_trigger_func();', EXECUTE FUNCTION dump_test.event_trigger_func();',
regexp => qr/^ regexp => qr/^
\QCREATE EVENT TRIGGER test_event_trigger \E \QCREATE EVENT TRIGGER test_event_trigger \E
\QON ddl_command_start\E \QON ddl_command_start\E
\n\s+\QEXECUTE PROCEDURE dump_test.event_trigger_func();\E \n\s+\QEXECUTE FUNCTION dump_test.event_trigger_func();\E
/xm, /xm,
like => { %full_runs, section_post_data => 1, }, like => { %full_runs, section_post_data => 1, },
}, },
...@@ -1554,11 +1554,11 @@ my %tests = ( ...@@ -1554,11 +1554,11 @@ my %tests = (
create_sql => 'CREATE TRIGGER test_trigger create_sql => 'CREATE TRIGGER test_trigger
BEFORE INSERT ON dump_test.test_table BEFORE INSERT ON dump_test.test_table
FOR EACH ROW WHEN (NEW.col1 > 10) FOR EACH ROW WHEN (NEW.col1 > 10)
EXECUTE PROCEDURE dump_test.trigger_func();', EXECUTE FUNCTION dump_test.trigger_func();',
regexp => qr/^ regexp => qr/^
\QCREATE TRIGGER test_trigger BEFORE INSERT ON dump_test.test_table \E \QCREATE TRIGGER test_trigger BEFORE INSERT ON dump_test.test_table \E
\QFOR EACH ROW WHEN ((new.col1 > 10)) \E \QFOR EACH ROW WHEN ((new.col1 > 10)) \E
\QEXECUTE PROCEDURE dump_test.trigger_func();\E \QEXECUTE FUNCTION dump_test.trigger_func();\E
/xm, /xm,
like => { like => {
%full_runs, %full_runs,
......
...@@ -53,6 +53,6 @@ ...@@ -53,6 +53,6 @@
*/ */
/* yyyymmddN */ /* yyyymmddN */
#define CATALOG_VERSION_NO 201902011 #define CATALOG_VERSION_NO 201902071
#endif #endif
...@@ -417,21 +417,21 @@ SELECT * FROM main_table ORDER BY a, b; ...@@ -417,21 +417,21 @@ SELECT * FROM main_table ORDER BY a, b;
(8 rows) (8 rows)
SELECT pg_get_triggerdef(oid, true) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_a'; SELECT pg_get_triggerdef(oid, true) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_a';
pg_get_triggerdef pg_get_triggerdef
-------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------
CREATE TRIGGER modified_a BEFORE UPDATE OF a ON main_table FOR EACH ROW WHEN (old.a <> new.a) EXECUTE PROCEDURE trigger_func('modified_a') CREATE TRIGGER modified_a BEFORE UPDATE OF a ON main_table FOR EACH ROW WHEN (old.a <> new.a) EXECUTE FUNCTION trigger_func('modified_a')
(1 row) (1 row)
SELECT pg_get_triggerdef(oid, false) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_a'; SELECT pg_get_triggerdef(oid, false) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_a';
pg_get_triggerdef pg_get_triggerdef
----------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------
CREATE TRIGGER modified_a BEFORE UPDATE OF a ON public.main_table FOR EACH ROW WHEN ((old.a <> new.a)) EXECUTE PROCEDURE trigger_func('modified_a') CREATE TRIGGER modified_a BEFORE UPDATE OF a ON public.main_table FOR EACH ROW WHEN ((old.a <> new.a)) EXECUTE FUNCTION trigger_func('modified_a')
(1 row) (1 row)
SELECT pg_get_triggerdef(oid, true) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_any'; SELECT pg_get_triggerdef(oid, true) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'modified_any';
pg_get_triggerdef pg_get_triggerdef
-------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE TRIGGER modified_any BEFORE UPDATE OF a ON main_table FOR EACH ROW WHEN (old.* IS DISTINCT FROM new.*) EXECUTE PROCEDURE trigger_func('modified_any') CREATE TRIGGER modified_any BEFORE UPDATE OF a ON main_table FOR EACH ROW WHEN (old.* IS DISTINCT FROM new.*) EXECUTE FUNCTION trigger_func('modified_any')
(1 row) (1 row)
-- Test RENAME TRIGGER -- Test RENAME TRIGGER
...@@ -477,9 +477,9 @@ FOR EACH STATEMENT EXECUTE PROCEDURE trigger_func('before_upd_a_stmt'); ...@@ -477,9 +477,9 @@ FOR EACH STATEMENT EXECUTE PROCEDURE trigger_func('before_upd_a_stmt');
CREATE TRIGGER after_upd_b_stmt_trig AFTER UPDATE OF b ON main_table CREATE TRIGGER after_upd_b_stmt_trig AFTER UPDATE OF b ON main_table
FOR EACH STATEMENT EXECUTE PROCEDURE trigger_func('after_upd_b_stmt'); FOR EACH STATEMENT EXECUTE PROCEDURE trigger_func('after_upd_b_stmt');
SELECT pg_get_triggerdef(oid) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'after_upd_a_b_row_trig'; SELECT pg_get_triggerdef(oid) FROM pg_trigger WHERE tgrelid = 'main_table'::regclass AND tgname = 'after_upd_a_b_row_trig';
pg_get_triggerdef pg_get_triggerdef
-------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------
CREATE TRIGGER after_upd_a_b_row_trig AFTER UPDATE OF a, b ON public.main_table FOR EACH ROW EXECUTE PROCEDURE trigger_func('after_upd_a_b_row') CREATE TRIGGER after_upd_a_b_row_trig AFTER UPDATE OF a, b ON public.main_table FOR EACH ROW EXECUTE FUNCTION trigger_func('after_upd_a_b_row')
(1 row) (1 row)
UPDATE main_table SET a = 50; UPDATE main_table SET a = 50;
...@@ -1107,15 +1107,15 @@ DELETE 1 ...@@ -1107,15 +1107,15 @@ DELETE 1
a | integer | | | a | integer | | |
b | integer | | | b | integer | | |
Triggers: Triggers:
after_del_stmt_trig AFTER DELETE ON main_view FOR EACH STATEMENT EXECUTE PROCEDURE view_trigger('after_view_del_stmt') after_del_stmt_trig AFTER DELETE ON main_view FOR EACH STATEMENT EXECUTE FUNCTION view_trigger('after_view_del_stmt')
after_ins_stmt_trig AFTER INSERT ON main_view FOR EACH STATEMENT EXECUTE PROCEDURE view_trigger('after_view_ins_stmt') after_ins_stmt_trig AFTER INSERT ON main_view FOR EACH STATEMENT EXECUTE FUNCTION view_trigger('after_view_ins_stmt')
after_upd_stmt_trig AFTER UPDATE ON main_view FOR EACH STATEMENT EXECUTE PROCEDURE view_trigger('after_view_upd_stmt') after_upd_stmt_trig AFTER UPDATE ON main_view FOR EACH STATEMENT EXECUTE FUNCTION view_trigger('after_view_upd_stmt')
before_del_stmt_trig BEFORE DELETE ON main_view FOR EACH STATEMENT EXECUTE PROCEDURE view_trigger('before_view_del_stmt') before_del_stmt_trig BEFORE DELETE ON main_view FOR EACH STATEMENT EXECUTE FUNCTION view_trigger('before_view_del_stmt')
before_ins_stmt_trig BEFORE INSERT ON main_view FOR EACH STATEMENT EXECUTE PROCEDURE view_trigger('before_view_ins_stmt') before_ins_stmt_trig BEFORE INSERT ON main_view FOR EACH STATEMENT EXECUTE FUNCTION view_trigger('before_view_ins_stmt')
before_upd_stmt_trig BEFORE UPDATE ON main_view FOR EACH STATEMENT EXECUTE PROCEDURE view_trigger('before_view_upd_stmt') before_upd_stmt_trig BEFORE UPDATE ON main_view FOR EACH STATEMENT EXECUTE FUNCTION view_trigger('before_view_upd_stmt')
instead_of_delete_trig INSTEAD OF DELETE ON main_view FOR EACH ROW EXECUTE PROCEDURE view_trigger('instead_of_del') instead_of_delete_trig INSTEAD OF DELETE ON main_view FOR EACH ROW EXECUTE FUNCTION view_trigger('instead_of_del')
instead_of_insert_trig INSTEAD OF INSERT ON main_view FOR EACH ROW EXECUTE PROCEDURE view_trigger('instead_of_ins') instead_of_insert_trig INSTEAD OF INSERT ON main_view FOR EACH ROW EXECUTE FUNCTION view_trigger('instead_of_ins')
instead_of_update_trig INSTEAD OF UPDATE ON main_view FOR EACH ROW EXECUTE PROCEDURE view_trigger('instead_of_upd') instead_of_update_trig INSTEAD OF UPDATE ON main_view FOR EACH ROW EXECUTE FUNCTION view_trigger('instead_of_upd')
-- Test dropping view triggers -- Test dropping view triggers
DROP TRIGGER instead_of_insert_trig ON main_view; DROP TRIGGER instead_of_insert_trig ON main_view;
...@@ -1131,13 +1131,13 @@ View definition: ...@@ -1131,13 +1131,13 @@ View definition:
main_table.b main_table.b
FROM main_table; FROM main_table;
Triggers: Triggers:
after_del_stmt_trig AFTER DELETE ON main_view FOR EACH STATEMENT EXECUTE PROCEDURE view_trigger('after_view_del_stmt') after_del_stmt_trig AFTER DELETE ON main_view FOR EACH STATEMENT EXECUTE FUNCTION view_trigger('after_view_del_stmt')
after_ins_stmt_trig AFTER INSERT ON main_view FOR EACH STATEMENT EXECUTE PROCEDURE view_trigger('after_view_ins_stmt') after_ins_stmt_trig AFTER INSERT ON main_view FOR EACH STATEMENT EXECUTE FUNCTION view_trigger('after_view_ins_stmt')
after_upd_stmt_trig AFTER UPDATE ON main_view FOR EACH STATEMENT EXECUTE PROCEDURE view_trigger('after_view_upd_stmt') after_upd_stmt_trig AFTER UPDATE ON main_view FOR EACH STATEMENT EXECUTE FUNCTION view_trigger('after_view_upd_stmt')
before_del_stmt_trig BEFORE DELETE ON main_view FOR EACH STATEMENT EXECUTE PROCEDURE view_trigger('before_view_del_stmt') before_del_stmt_trig BEFORE DELETE ON main_view FOR EACH STATEMENT EXECUTE FUNCTION view_trigger('before_view_del_stmt')
before_ins_stmt_trig BEFORE INSERT ON main_view FOR EACH STATEMENT EXECUTE PROCEDURE view_trigger('before_view_ins_stmt') before_ins_stmt_trig BEFORE INSERT ON main_view FOR EACH STATEMENT EXECUTE FUNCTION view_trigger('before_view_ins_stmt')
before_upd_stmt_trig BEFORE UPDATE ON main_view FOR EACH STATEMENT EXECUTE PROCEDURE view_trigger('before_view_upd_stmt') before_upd_stmt_trig BEFORE UPDATE ON main_view FOR EACH STATEMENT EXECUTE FUNCTION view_trigger('before_view_upd_stmt')
instead_of_update_trig INSTEAD OF UPDATE ON main_view FOR EACH ROW EXECUTE PROCEDURE view_trigger('instead_of_upd') instead_of_update_trig INSTEAD OF UPDATE ON main_view FOR EACH ROW EXECUTE FUNCTION view_trigger('instead_of_upd')
DROP VIEW main_view; DROP VIEW main_view;
-- --
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment