Skip to content

Instantly share code, notes, and snippets.

@bastman
Last active June 25, 2020 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bastman/8986ee5989317fcb3c78f4d2d84b97d2 to your computer and use it in GitHub Desktop.
Save bastman/8986ee5989317fcb3c78f4d2d84b97d2 to your computer and use it in GitHub Desktop.
postgres: explore primary keys
SELECT my_id, COUNT(my_id)
FROM my_table
GROUP BY my_id
HAVING COUNT(my_id) > 1;
select table_name, table_schema from information_schema."tables"
where table_name not in (
select table_name from information_schema.table_constraints where constraint_type='PRIMARY KEY'
) and table_schema='public';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment