I tried to use the code suggested on the Postgresql wiki (https://wiki.postgresql.org/wiki/Retrieve_primary_key_columns):
SELECT a.attname, format_type(a.atttypid, a.atttypmod) AS data_type
FROM pg_index i
JOIN pg_attribute a ON a.attrelid = i.indrelid
AND a.attnum = ANY(i.indkey)
WHERE i.indrelid = 'tablename'::regclass
AND i.indisprimary;
Unfortunately, it doesn't seem to work in Redshift. And I get this error:
ERROR: op ANY/ALL (array) requires array on right side
Am I doing something wrong or is this yet another redshift anomaly?
Any help would be greatly appreciated.