From c874248781c0e7131eb08b72cb46bac4b9fda2d5 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Thu, 31 Dec 2009 14:41:23 +0000 Subject: [PATCH] Add information_schema.triggered_update_columns This reflects the recently added support for triggers on columns. --- doc/src/sgml/information_schema.sgml | 74 ++++++++++++++++++++++ src/backend/catalog/information_schema.sql | 26 ++++++-- 2 files changed, 94 insertions(+), 6 deletions(-) diff --git a/doc/src/sgml/information_schema.sgml b/doc/src/sgml/information_schema.sgml index 9e3ace0696..97e95ed6a2 100644 --- a/doc/src/sgml/information_schema.sgml +++ b/doc/src/sgml/information_schema.sgml @@ -4796,6 +4796,80 @@ ORDER BY c.ordinal_position; + + <literal>triggered_update_columns</literal> + + + For triggers in the current database that specify a column list + (like UPDATE OF column1, column2), the + view triggered_update_columns identifies these + columns. Triggers that do not specify a column list are not + included in this view. Only those columns are shown that the + current user owns or has some non-SELECT privilege on. + + + + <literal>triggered_update_columns</literal> Columns + + + + + Name + Data Type + Description + + + + + + trigger_catalog + sql_identifier + Name of the database that contains the trigger (always the current database) + + + + trigger_schema + sql_identifier + Name of the schema that contains the trigger + + + + trigger_name + sql_identifier + Name of the trigger + + + + event_object_catalog + sql_identifier + + Name of the database that contains the table that the trigger + is defined on (always the current database) + + + + + event_object_schema + sql_identifier + Name of the schema that contains the table that the trigger is defined on + + + + event_object_table + sql_identifier + Name of the table that the trigger is defined on + + + + event_object_column + sql_identifier + Name of the column that the trigger is defined on + + + +
+
+ <literal>triggers</literal> diff --git a/src/backend/catalog/information_schema.sql b/src/backend/catalog/information_schema.sql index 6edebaf87e..72f8cc1384 100644 --- a/src/backend/catalog/information_schema.sql +++ b/src/backend/catalog/information_schema.sql @@ -1852,13 +1852,27 @@ GRANT SELECT ON tables TO PUBLIC; CREATE VIEW triggered_update_columns AS SELECT CAST(current_database() AS sql_identifier) AS trigger_catalog, - CAST(null AS sql_identifier) AS trigger_schema, - CAST(null AS sql_identifier) AS trigger_name, + CAST(n.nspname AS sql_identifier) AS trigger_schema, + CAST(t.tgname AS sql_identifier) AS trigger_name, CAST(current_database() AS sql_identifier) AS event_object_catalog, - CAST(null AS sql_identifier) AS event_object_schema, - CAST(null AS sql_identifier) AS event_object_table, - CAST(null AS sql_identifier) AS event_object_column - WHERE false; + CAST(n.nspname AS sql_identifier) AS event_object_schema, + CAST(c.relname AS sql_identifier) AS event_object_table, + CAST(a.attname AS sql_identifier) AS event_object_column + + FROM pg_namespace n, pg_class c, pg_trigger t, + (SELECT tgoid, (ta0.tgat).x AS tgattnum, (ta0.tgat).n AS tgattpos + FROM (SELECT oid AS tgoid, information_schema._pg_expandarray(tgattr) AS tgat FROM pg_trigger) AS ta0) AS ta, + pg_attribute a + + WHERE n.oid = c.relnamespace + AND c.oid = t.tgrelid + AND t.oid = ta.tgoid + AND (a.attrelid, a.attnum) = (t.tgrelid, ta.tgattnum) + AND NOT t.tgisconstraint + AND (NOT pg_is_other_temp_schema(n.oid)) + AND (pg_has_role(c.relowner, 'USAGE') + -- SELECT privilege omitted, per SQL standard + OR has_column_privilege(c.oid, a.attnum, 'INSERT, UPDATE, REFERENCES') ); GRANT SELECT ON triggered_update_columns TO PUBLIC; -- 2.39.5