Commit 32ff2691 authored by Peter Eisentraut's avatar Peter Eisentraut

Add more information_schema columns

- table_constraints.enforced
- triggers.action_order
- triggers.action_reference_old_table
- triggers.action_reference_new_table
Reviewed-by: default avatarMichael Paquier <michael.paquier@gmail.com>
parent b98a7cd5
...@@ -5317,6 +5317,13 @@ ORDER BY c.ordinal_position; ...@@ -5317,6 +5317,13 @@ ORDER BY c.ordinal_position;
<entry><type>yes_or_no</type></entry> <entry><type>yes_or_no</type></entry>
<entry><literal>YES</literal> if the constraint is deferrable and initially deferred, <literal>NO</literal> if not</entry> <entry><literal>YES</literal> if the constraint is deferrable and initially deferred, <literal>NO</literal> if not</entry>
</row> </row>
<row>
<entry><literal>enforced</literal></entry>
<entry><type>yes_or_no</type></entry>
<entry>Applies to a feature not available in
<productname>PostgreSQL</productname> (currently always
<literal>YES</literal>)</entry>
</row>
</tbody> </tbody>
</tgroup> </tgroup>
</table> </table>
...@@ -5761,7 +5768,14 @@ ORDER BY c.ordinal_position; ...@@ -5761,7 +5768,14 @@ ORDER BY c.ordinal_position;
<row> <row>
<entry><literal>action_order</literal></entry> <entry><literal>action_order</literal></entry>
<entry><type>cardinal_number</type></entry> <entry><type>cardinal_number</type></entry>
<entry>Not yet implemented</entry> <entry>
Firing order among triggers on the same table having the same
<literal>event_manipulation</literal>,
<literal>action_timing</literal>, and
<literal>action_orientation</literal>. In
<productname>PostgreSQL</productname>, triggers are fired in name
order, so this column reflects that.
</entry>
</row> </row>
<row> <row>
...@@ -5806,13 +5820,13 @@ ORDER BY c.ordinal_position; ...@@ -5806,13 +5820,13 @@ ORDER BY c.ordinal_position;
<row> <row>
<entry><literal>action_reference_old_table</literal></entry> <entry><literal>action_reference_old_table</literal></entry>
<entry><type>sql_identifier</type></entry> <entry><type>sql_identifier</type></entry>
<entry>Applies to a feature not available in <productname>PostgreSQL</productname></entry> <entry>Name of the <quote>old</quote> transition table, or null if none</entry>
</row> </row>
<row> <row>
<entry><literal>action_reference_new_table</literal></entry> <entry><literal>action_reference_new_table</literal></entry>
<entry><type>sql_identifier</type></entry> <entry><type>sql_identifier</type></entry>
<entry>Applies to a feature not available in <productname>PostgreSQL</productname></entry> <entry>Name of the <quote>new</quote> transition table, or null if none</entry>
</row> </row>
<row> <row>
......
...@@ -1783,7 +1783,8 @@ CREATE VIEW table_constraints AS ...@@ -1783,7 +1783,8 @@ CREATE VIEW table_constraints AS
CAST(CASE WHEN c.condeferrable THEN 'YES' ELSE 'NO' END AS yes_or_no) CAST(CASE WHEN c.condeferrable THEN 'YES' ELSE 'NO' END AS yes_or_no)
AS is_deferrable, AS is_deferrable,
CAST(CASE WHEN c.condeferred THEN 'YES' ELSE 'NO' END AS yes_or_no) CAST(CASE WHEN c.condeferred THEN 'YES' ELSE 'NO' END AS yes_or_no)
AS initially_deferred AS initially_deferred,
CAST('YES' AS yes_or_no) AS enforced
FROM pg_namespace nc, FROM pg_namespace nc,
pg_namespace nr, pg_namespace nr,
...@@ -1812,7 +1813,8 @@ CREATE VIEW table_constraints AS ...@@ -1812,7 +1813,8 @@ CREATE VIEW table_constraints AS
CAST(r.relname AS sql_identifier) AS table_name, CAST(r.relname AS sql_identifier) AS table_name,
CAST('CHECK' AS character_data) AS constraint_type, CAST('CHECK' AS character_data) AS constraint_type,
CAST('NO' AS yes_or_no) AS is_deferrable, CAST('NO' AS yes_or_no) AS is_deferrable,
CAST('NO' AS yes_or_no) AS initially_deferred CAST('NO' AS yes_or_no) AS initially_deferred,
CAST('YES' AS yes_or_no) AS enforced
FROM pg_namespace nr, FROM pg_namespace nr,
pg_class r, pg_class r,
...@@ -2084,8 +2086,12 @@ CREATE VIEW triggers AS ...@@ -2084,8 +2086,12 @@ CREATE VIEW triggers AS
CAST(current_database() AS sql_identifier) AS event_object_catalog, CAST(current_database() AS sql_identifier) AS event_object_catalog,
CAST(n.nspname AS sql_identifier) AS event_object_schema, CAST(n.nspname AS sql_identifier) AS event_object_schema,
CAST(c.relname AS sql_identifier) AS event_object_table, CAST(c.relname AS sql_identifier) AS event_object_table,
CAST(null AS cardinal_number) AS action_order, CAST(
-- XXX strange hacks follow -- To determine action order, partition by schema, table,
-- event_manipulation (INSERT/DELETE/UPDATE), ROW/STATEMENT (1),
-- BEFORE/AFTER (66), then order by trigger name
rank() OVER (PARTITION BY n.oid, c.oid, em.num, t.tgtype & 1, t.tgtype & 66 ORDER BY t.tgname)
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 PROCEDURE'))[1]
...@@ -2103,8 +2109,8 @@ CREATE VIEW triggers AS ...@@ -2103,8 +2109,8 @@ CREATE VIEW triggers AS
-- hard-wired refs to TRIGGER_TYPE_BEFORE, TRIGGER_TYPE_INSTEAD -- hard-wired refs to TRIGGER_TYPE_BEFORE, TRIGGER_TYPE_INSTEAD
CASE t.tgtype & 66 WHEN 2 THEN 'BEFORE' WHEN 64 THEN 'INSTEAD OF' ELSE 'AFTER' END CASE t.tgtype & 66 WHEN 2 THEN 'BEFORE' WHEN 64 THEN 'INSTEAD OF' ELSE 'AFTER' END
AS character_data) AS action_timing, AS character_data) AS action_timing,
CAST(null AS sql_identifier) AS action_reference_old_table, CAST(tgoldtable AS sql_identifier) AS action_reference_old_table,
CAST(null AS sql_identifier) AS action_reference_new_table, CAST(tgnewtable AS sql_identifier) AS action_reference_new_table,
CAST(null AS sql_identifier) AS action_reference_old_row, CAST(null AS sql_identifier) AS action_reference_old_row,
CAST(null AS sql_identifier) AS action_reference_new_row, CAST(null AS sql_identifier) AS action_reference_new_row,
CAST(null AS time_stamp) AS created CAST(null AS time_stamp) AS created
......
This diff is collapsed.
...@@ -92,6 +92,11 @@ delete from pkeys where pkey1 = 40 and pkey2 = '4'; ...@@ -92,6 +92,11 @@ delete from pkeys where pkey1 = 40 and pkey2 = '4';
update pkeys set pkey1 = 7, pkey2 = '70' where pkey1 = 50 and pkey2 = '5'; update pkeys set pkey1 = 7, pkey2 = '70' where pkey1 = 50 and pkey2 = '5';
update pkeys set pkey1 = 7, pkey2 = '70' where pkey1 = 10 and pkey2 = '1'; update pkeys set pkey1 = 7, pkey2 = '70' where pkey1 = 10 and pkey2 = '1';
SELECT trigger_name, event_manipulation, event_object_schema, event_object_table,
action_order, action_condition, action_orientation, action_timing,
action_reference_old_table, action_reference_new_table
FROM information_schema.triggers ORDER BY 1, 2;
DROP TABLE pkeys; DROP TABLE pkeys;
DROP TABLE fkeys; DROP TABLE fkeys;
DROP TABLE fkeys2; DROP TABLE fkeys2;
...@@ -279,6 +284,10 @@ CREATE TRIGGER insert_when BEFORE INSERT ON main_table ...@@ -279,6 +284,10 @@ CREATE TRIGGER insert_when BEFORE INSERT ON main_table
FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE trigger_func('insert_when'); FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE trigger_func('insert_when');
CREATE TRIGGER delete_when AFTER DELETE ON main_table CREATE TRIGGER delete_when AFTER DELETE ON main_table
FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE trigger_func('delete_when'); FOR EACH STATEMENT WHEN (true) EXECUTE PROCEDURE trigger_func('delete_when');
SELECT trigger_name, event_manipulation, event_object_schema, event_object_table,
action_order, action_condition, action_orientation, action_timing,
action_reference_old_table, action_reference_new_table
FROM information_schema.triggers ORDER BY 1, 2;
INSERT INTO main_table (a) VALUES (123), (456); INSERT INTO main_table (a) VALUES (123), (456);
COPY main_table FROM stdin; COPY main_table FROM stdin;
123 999 123 999
...@@ -1472,6 +1481,11 @@ create trigger child3_delete_trig ...@@ -1472,6 +1481,11 @@ create trigger child3_delete_trig
after delete on child3 referencing old table as old_table after delete on child3 referencing old table as old_table
for each statement execute procedure dump_delete(); for each statement execute procedure dump_delete();
SELECT trigger_name, event_manipulation, event_object_schema, event_object_table,
action_order, action_condition, action_orientation, action_timing,
action_reference_old_table, action_reference_new_table
FROM information_schema.triggers ORDER BY 1, 2;
-- insert directly into children sees respective child-format tuples -- insert directly into children sees respective child-format tuples
insert into child1 values ('AAA', 42); insert into child1 values ('AAA', 42);
insert into child2 values ('BBB', 42); insert into child2 values ('BBB', 42);
......
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