Database Reference
In-Depth Information
GROUP BY column_name
HAVING count(*) > 1
)
AND table_schema NOT IN ('information_schema', 'pg_catalog')
ORDER BY column_name
;
gives output, such as the following:
table_schema | table_name | column_name | data_type
--------------+------------+-------------+---------------
s2 | x | col1 | integer 32,0
s1 | x | col1 | smallint 16,0
(2 rows)
Tables
Comparing two tables is more complex, as there are so many ways that a table might be
similar and yet a little different. The following query looks for all tables of the same name (and
hence in different schemas) that have different definitions:
SELECT
table_schema
,table_name
,column_name
,data_type
FROM information_schema.columns
WHERE table_name IN
(SELECT
table_name
FROM
(SELECT
table_schema
,table_name
,string_agg(' '||column_name||' '||data_type)
FROM information_schema.columns
GROUP BY
table_schema
,table_name
) def
GROUP BY
table_name
HAVING
count(*) > 1
)
ORDER BY
 
Search WWH ::




Custom Search