我已阅读了几个问题,但它没有解决我对PostgreSql的问题。
我正在尝试从多个表创建一个View,但是当它实际上在“ ContextLink ”列上时,模式的以下部分会返回“列不存在”错误。我对其他专栏没有同样的问题,所以在解决这个问题时我有点迷失。
Postgres返回
O(|V|*|V|)
我希望我在这里不会错过任何愚蠢的话。 非常感谢您的帮助。
干杯,
答案 0 :(得分: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");