2017-11-06 12 views
0

私はいくつかの質問を読んだが、PostgreSQLとの問題は解決しなかった。postgresqlカラムが合体に存在しません

複数の表からビューを作成しようとしましたが、実際に両方の列 "ContextLink"で実際にスキーマの次の部分が "列は存在しません"というエラーを返します。私は他の列と同じ問題はありませんが、この問題の解決方法については少し失われています。

Postgresは私がここに愚かな何かが欠けておりません願ってい

ERROR: The column ProjectReferenceDataLibrary_BaseUnit.ContextLink 
does not exist 
LINE 1218:   COALESCE("ProjectReferenceDataLibrary_BaseUnit"."Con... 
         ^
SQL state: 42703 
Character: 74151 

    -- Create link table for class ProjectReferenceDataLibrary 
CREATE TABLE "Directory"."ProjectReferenceDataLibrary_BaseUnit" (
    "ContextLink" varchar NOT NULL, 
    "ProjectReferenceDataLibrary" uuid NOT NULL, 
    "BaseUnit" uuid NOT NULL 
); 

-- Create link table for class ProjectReferenceDataLibrary 
CREATE TABLE "Directory"."ProjectReferenceDataLibrary_BaseQuantityKind" (
    "ContextLink" text NOT NULL, 
    "ProjectReferenceDataLibrary" uuid NOT NULL, 
    "BaseQuantityKind" uuid NOT NULL, 
    "OrderKey" bigint NOT NULL 
); 

CREATE VIEW "Directory"."ProjectReferenceDataLibrary_View" AS 
    SELECT "ProjectReferenceDataLibrary"."UniqueIdentifier", "ProjectReferenceDataLibrary"."ValueTypeDictionary" AS "ValueTypeSet", 
     "ProjectReferenceDataLibrary"."Container", 
     COALESCE("ProjectReferenceDataLibrary_BaseUnit"."BaseUnit",'{}'::text[]) AS "BaseUnit", 
     COALESCE("ProjectReferenceDataLibrary_BaseUnit"."ContextLink",'{}'::text[]) AS "BaseUnit_ContextLink", 
     COALESCE("ProjectReferenceDataLibrary_BaseQuantityKind"."BaseQuantityKind",'{}'::text[]) AS "BaseQuantityKind", 
     COALESCE("ProjectReferenceDataLibrary_BaseQuantityKind"."ContextLink",'{}'::text[]) AS "BaseQuantityKind_ContextLink" 
FROM "Directory"."ProjectReferenceDataLibrary" AS "ProjectReferenceDataLibrary" 
LEFT JOIN (SELECT "ProjectReferenceDataLibrary" AS "UniqueIdentifier", array_agg("BaseUnit"::text) AS "BaseUnit", array_agg("ContextLink"::text) AS "BaseUnit_ContextLink" 
    FROM "Directory"."ProjectReferenceDataLibrary_BaseUnit" 
    JOIN "Directory"."ProjectReferenceDataLibrary" AS "ProjectReferenceDataLibrary" ON "ProjectReferenceDataLibrary" = "UniqueIdentifier" 
    GROUP BY "ProjectReferenceDataLibrary") AS "ProjectReferenceDataLibrary_BaseUnit" USING ("UniqueIdentifier") 
LEFT JOIN (SELECT "ProjectReferenceDataLibrary" AS "UniqueIdentifier", ARRAY[array_agg("OrderKey"::text), array_agg("BaseQuantityKind"::text)] AS "BaseQuantityKind", array_agg("ContextLink"::text) AS "BaseQuantityKind_ContextLink" 
    FROM "Directory"."ProjectReferenceDataLibrary_BaseQuantityKind" 
    JOIN "Directory"."ProjectReferenceDataLibrary" AS "ProjectReferenceDataLibrary" ON "ProjectReferenceDataLibrary" = "UniqueIdentifier" 
    GROUP BY "ProjectReferenceDataLibrary") AS "ProjectReferenceDataLibrary_BaseQuantityKind" USING ("UniqueIdentifier"); 

を返します。 ご協力いただきありがとうございます。

乾杯、

+0

どこFROM句のですか? –

+0

申し訳ありませんが、FROMは関連性があるとは思わなかったが、投稿を編集して – icykof

+0

にFROM句を付けないと、列が見つからない理由を追跡することはできません.... –

答えて

0

The column ProjectReferenceDataLibrary_BaseUnit.ContextLink does not existはクエリの外側のレベルでbase_unitのサブクエリがBaseUnit_ContextLinkに、その列の名前を変更した、正確です。したがって、その外部層で行うすべての参照がサブクエリの列エイリアスを使用していることを確認する必要があります。

これを試してみてください。

CREATE VIEW "Directory"."ProjectReferenceDataLibrary_View" AS 
SELECT "ProjectReferenceDataLibrary"."UniqueIdentifier", 
      "ProjectReferenceDataLibrary"."ValueTypeDictionary" AS "ValueTypeSet", 
      "ProjectReferenceDataLibrary"."Container", 
      COALESCE("ProjectReferenceDataLibrary_BaseUnit"."BaseUnit",'{}'::text[])     AS "BaseUnit", 
      COALESCE("ProjectReferenceDataLibrary_BaseUnit"."BaseUnit_ContextLink",'{}'::text[])    AS "BaseUnit_ContextLink", 
      COALESCE("ProjectReferenceDataLibrary_BaseQuantityKind"."BaseQuantityKind",'{}'::text[]) AS "BaseQuantityKind", 
      COALESCE("ProjectReferenceDataLibrary_BaseQuantityKind"."BaseQuantityKind_ContextLink",'{}'::text[])  AS "BaseQuantityKind_ContextLink" 
FROM  "Directory"."ProjectReferenceDataLibrary"            AS "ProjectReferenceDataLibrary" 
LEFT JOIN 
      ( 
        SELECT "ProjectReferenceDataLibrary" AS "UniqueIdentifier", 
          array_agg("BaseUnit"::text) AS "BaseUnit", 
          array_agg("ContextLink"::text) AS "BaseUnit_ContextLink" 
        FROM  "Directory"."ProjectReferenceDataLibrary_BaseUnit" 
        JOIN  "Directory"."ProjectReferenceDataLibrary" AS "ProjectReferenceDataLibrary" 
        ON  "ProjectReferenceDataLibrary" = "UniqueIdentifier" 
        GROUP BY "ProjectReferenceDataLibrary") AS "ProjectReferenceDataLibrary_BaseUnit" 
using  ("UniqueIdentifier") 
LEFT JOIN 
      ( 
        SELECT "ProjectReferenceDataLibrary"           AS "UniqueIdentifier", 
          array[array_agg("OrderKey"::text), array_agg("BaseQuantityKind"::text)] AS "BaseQuantityKind", 
          array_agg("ContextLink"::text)           AS "BaseQuantityKind_ContextLink" 
        FROM  "Directory"."ProjectReferenceDataLibrary_BaseQuantityKind" 
        JOIN  "Directory"."ProjectReferenceDataLibrary" AS "ProjectReferenceDataLibrary" 
        ON  "ProjectReferenceDataLibrary" = "UniqueIdentifier" 
        GROUP BY "ProjectReferenceDataLibrary") AS "ProjectReferenceDataLibrary_BaseQuantityKind" 
using  ("UniqueIdentifier"); 
+0

ああ、エイリアスの問題...ご指摘いただきありがとうございます。私はこれらのpostgresql構文に精通していないので、COALESCEが実際のテーブルの列を指していると思いました。 – icykof

+0

あまりにも多くのコードはPostgres固有のもので、私の意見では ':: stuff'としか書いていません。すべての二重引用符を取り除き、b。方法の短いテーブルエイリアスを使用しますが、それはちょうど意見です –

関連する問題