Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon Redshift get list of identity columns for a table

How can I get a list of identity columns for a table in Amazon Redshift? (using system's tables)

Thank you.

like image 427
Majid Darabi Avatar asked Dec 06 '25 17:12

Majid Darabi


1 Answers

For those who might be interested to know about how to get all identity columns in a Redshift DB. The following query was posted by Neil@AWS to AWS Redshift Forum:

select 
    c.relname, 
    a.attname 
from pg_class c, pg_attribute a, pg_attrdef d 
where c.oid = a.attrelid 
    and c.relkind = 'r' 
    and a.attrelid = d.adrelid 
    and a.attnum = d.adnum 
    and d.adsrc like '%identity%' 
order by 1;
like image 177
Majid Darabi Avatar answered Dec 11 '25 21:12

Majid Darabi