Created
May 22, 2014 16:29
-
-
Save dbaston/0969735b4a7b75a6a974 to your computer and use it in GitHub Desktop.
Compare structure of two tables
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 old.column_name as column_1141, old.data_type as type_1141, new.column_name as column_1142, new.data_type as type_1142 | |
FROM | |
(SELECT * FROM information_schema.columns WHERE table_schema = 'old_schema' AND table_name = 'old_table') old | |
FULL OUTER JOIN | |
(SELECT * FROM information_schema.columns WHERE table_schema = 'new_schema' AND table_name = 'new_table') new | |
USING (column_name) | |
WHERE old.column_name IS DISTINCT FROM new.column_name | |
OR old.data_type != new.data_type | |
ORDER BY COALESCE(old.column_name, new.column_name) ASC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment