Skip to content

Instantly share code, notes, and snippets.

@dbaston
Created May 22, 2014 16:29
Show Gist options
  • Save dbaston/0969735b4a7b75a6a974 to your computer and use it in GitHub Desktop.
Save dbaston/0969735b4a7b75a6a974 to your computer and use it in GitHub Desktop.
Compare structure of two tables
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