2016-04-20 33 views
1

私たちはPostgres 8を使用しているRedshiftを使用しています。
私は(2)テーブルを比較する必要がありますが、私は列の違いを見つける必要があります。postgresql - 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, 
) 

答えて

1

あなたはtable1には表示されませんtable2からすべての列名を選択することによって、これを達成することができます

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' 
    ) 
+0

これは私のために動作します。ありがとうございました。 – noober

関連する問題