Redshift Observatory

System Table Tracker

System view information_schema.constraint_column_usage version 1.0.43331 / 2022-11-04

schema name column data type
information_schema constraint_column_usage column_name sql_identifier
information_schema constraint_column_usage constraint_catalog sql_identifier
information_schema constraint_column_usage constraint_name sql_identifier
information_schema constraint_column_usage constraint_schema sql_identifier
information_schema constraint_column_usage table_catalog sql_identifier
information_schema constraint_column_usage table_name sql_identifier
information_schema constraint_column_usage table_schema sql_identifier

View Text

SELECT CAST(current_database() AS information_schema.sql_identifier) AS table_catalog,
       CAST(x.tblschema AS information_schema.sql_identifier) AS table_schema,
       CAST(x.tblname AS information_schema.sql_identifier) AS table_name,
       CAST(x.colname AS information_schema.sql_identifier) AS column_name,
       CAST(current_database() AS information_schema.sql_identifier) AS constraint_catalog,
       CAST(x.cstrschema AS information_schema.sql_identifier) AS constraint_schema,
       CAST(x.cstrname AS information_schema.sql_identifier) AS constraint_name
FROM (SELECT DISTINCT nr.nspname,
                      r.relname,
                      r.relowner,
                      a.attname,
                      nc.nspname,
                      c.conname
      FROM pg_namespace AS nr, pg_class AS r, pg_attribute AS a, pg_depend AS d, pg_namespace AS nc, pg_constraint AS c
      WHERE nr.oid = r.relnamespace
        AND r.oid = a.attrelid
        AND d.refclassid = CAST(CAST('pg_class' AS regclass) AS oid)
        AND d.refobjid = r.oid
        AND d.refobjsubid = a.attnum
        AND d.classid = CAST(CAST('pg_constraint' AS regclass) AS oid)
        AND d.objid = c.oid
        AND c.connamespace = nc.oid
        AND c.contype = CAST('c' AS "char")
        AND r.relkind = CAST('r' AS "char")
        AND NOT a.attisdropped

      UNION ALL

      SELECT nr.nspname,
             r.relname,
             r.relowner,
             a.attname,
             nc.nspname,
             c.conname
      FROM pg_namespace AS nr,
           pg_class AS r,
           pg_attribute AS a,
           pg_namespace AS nc,
           pg_constraint AS c,
           information_schema._pg_keypositions() AS pos (n)
      WHERE nr.oid = r.relnamespace
        AND r.oid = a.attrelid
        AND nc.oid = c.connamespace
        AND CASE
              WHEN c.contype = CAST('f' AS "char")
                THEN r.oid = c.confrelid
                 AND (c.confkey)[pos.n] = a.attnum
              ELSE r.oid = c.conrelid
               AND (c.conkey)[pos.n] = a.attnum
            END
        AND NOT a.attisdropped
        AND (c.contype = CAST('p' AS "char")
          OR c.contype = CAST('u' AS "char")
          OR c.contype = CAST('f' AS "char"))
        AND r.relkind = CAST('r' AS "char")) AS x (tblschema, tblname, tblowner, colname, cstrschema, cstrname),
     pg_user AS u
WHERE x.tblowner = u.usesysid
  AND u.usename = CAST("current_user"() AS name)


Home 3D Друк Blog Bring-Up Times Consultancy Cross-Region Benchmarks Email Forums IRC Mailing Lists Reddit Redshift Price Tracker Redshift Version Tracker Redshift Workbench System Table Tracker The Known Universe Twitter White Papers