-- `PERFORM` isn't used because it doesn't allow `WITH`
defstext:=$b$
-- Delete
CREATEFUNCTIONr.thing_delete_statement()
RETURNSTRIGGER
LANGUAGEplpgsql
AS$$
DECLARE
fooint;
BEGIN
WITHcombined_transition_tablesAS(
select_old_table
),
trigger_resultAScommand
SELECT
1INTOfoo;
delete_command;
RETURNNULL;
END$$;
CREATETRIGGERdelete_statement
@ -82,15 +74,8 @@ END $$;
RETURNSTRIGGER
LANGUAGEplpgsql
AS$$
DECLARE
fooint;
BEGIN
WITHcombined_transition_tablesAS(
select_new_table
),
trigger_resultAScommand
SELECT
1INTOfoo;
insert_command;
RETURNNULL;
END$$;
CREATETRIGGERinsert_statement
@ -102,16 +87,8 @@ END $$;
RETURNSTRIGGER
LANGUAGEplpgsql
AS$$
DECLARE
fooint;
BEGIN
WITHcombined_transition_tablesAS(
select_old_table
UNIONALLselect_new_table
),
trigger_resultAScommand
SELECT
1INTOfoo;
update_command;
RETURNNULL;
END$$;
CREATETRIGGERupdate_statement
@ -120,6 +97,10 @@ END $$;
EXECUTEFUNCTIONr.thing_update_statement();
$b$;
BEGIN
-- Couldn't get `combined_transition_tables` to work using CTE
defs:=replace(defs,'delete_command',replace(command,'combined_transition_tables','(select_old_table) AS combined_transition_tables'));
defs:=replace(defs,'insert_command',replace(command,'combined_transition_tables','(select_new_table) AS combined_transition_tables'));
defs:=replace(defs,'update_command',replace(command,'combined_transition_tables','(select_old_table UNION ALL select_new_table) AS combined_transition_tables'));