我们正在使用正在使用Postgres 8的Redshift 我需要比较(2)几乎相同的表,但另一个表将有额外的列,所以,我需要找出列的差异。
示例:
CREATE TABLE table1 (
v_id character varying(255) NOT NULL,
v_created timestamp without time zone NOT NULL,
abc_102 boolean,
abc_103 boolean,
abc_104 boolean,
def_56 boolean DEFAULT false NOT NULL,
def_57 boolean DEFAULT false NOT NULL
)
CREATE TABLE table2 (
v_id character varying(255) NOT NULL,
v_created timestamp without time zone NOT NULL,
abc_102 boolean,
abc_103 boolean,
abc_104 boolean,
abc_105 boolean,
def_56 boolean DEFAULT false NOT NULL,
def_57 boolean DEFAULT false NOT NULL,
def_58 boolean DEFAULT false NOT NULL,
)
我可以使用哪种查询来查看列差异列表?
答案 0 :(得分:1)
您可以通过选择table2
中的所有列名来实现此目的, not 也会出现在table1
中:
SELECT column_name
FROM information_schema.columns
WHERE table_schema = 'your_schema' AND table_name = 'table2'
AND column_name NOT IN
(
SELECT column_name
FROM information_schema.columns
WHERE table_schema = 'your_schema' AND table_name = 'table1'
)