postgresql-获取两个表之间差异的列列表
我们使用的是红移,它使用的是Postgres 8。postgresql-获取两个表之间差异的列列表,postgresql,psql,Postgresql,Psql,我们使用的是红移,它使用的是Postgres 8。 我需要比较(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,
我需要比较(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,
)
我可以使用什么查询来提供列差异列表?您可以通过从
表2
中选择所有不在表1
中出现的列名来实现这一点:
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'
)