Last active
June 25, 2020 07:49
-
-
Save bastman/8986ee5989317fcb3c78f4d2d84b97d2 to your computer and use it in GitHub Desktop.
postgres: explore primary keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT my_id, COUNT(my_id) | |
FROM my_table | |
GROUP BY my_id | |
HAVING COUNT(my_id) > 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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