简体   繁体   中英

Redshift column names

I'm new to redshift. I have some tables in 'abc' schema whose column names and primary key information needs to be extracted. Can someone guide. Assume schema name is 'abc' and table name is 'xyz' whose columns are required to be listed in a single row.

使用AWS Labs提供的v_generate_tbl_ddl.sql ,您可以使用表级或架构级过滤器。

You can query the SVV_COLUMNS table. It includes:

  • Scheme Name
  • Table Name
  • Column Name

I used this query to get a list of primary keys. A lot of additional info can be added. Postres official documentation to pg_ tables helps a lot.

SELECT
    f.attname AS column_name
FROM
    pg_catalog.pg_namespace n
JOIN pg_catalog.pg_class c ON
    n.oid = c.relnamespace
JOIN pg_catalog.pg_attribute f ON
    c.oid = f.attrelid
JOIN pg_catalog.pg_constraint p ON
    p.conrelid = c.oid
    AND f.attnum = ANY (p.conkey)
WHERE
    n.nspname = 'schema_name'
    AND c.relkind = 'r'
    AND c.relname = 'table_name'
    AND p.contype = 'p'
    AND f.attnum > 0
ORDER BY
    f.attnum;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM