Skip to content

Instantly share code, notes, and snippets.

@yujihamaguchi
Last active August 29, 2015 14:04
Show Gist options
  • Save yujihamaguchi/ded69bbf53227eea1616 to your computer and use it in GitHub Desktop.
Save yujihamaguchi/ded69bbf53227eea1616 to your computer and use it in GitHub Desktop.
[Redshift] 主キー情報取得
SELECT
nspname
,relname
,conname
,attnum
,attname
,conkey
FROM
pg_constraint r1
,pg_namespace r2
,pg_class r3
,pg_attribute r4
WHERE
contype = 'p'
AND conrelid = r3.oid
AND conrelid = r4.attrelid
AND r3.relnamespace = r2.oid
AND r4.attnum = ANY(r1.conkey)
AND nspname = 'wrk'
AND relname = 'x'
ORDER BY
1,2,3,4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment