我有一个用户定义的函数这个复杂的查询conta_relatos()
运行得很好,select语句。 但是,当我尝试创建一个具有相同指令的观点是行不通的。 Postgres的告诉我,列“conta_relatos”有伪类型的记录。 此功能, conta_relatos()
返回一个记录类型的变量。
除了通过编辑:
返回类型是如在前面的问题限定的公知的复合类型:
Postgres的函数结束循环,并返回错误
下面是查询:
CREATE OR REPLACE VIEW "Sumario" AS
SELECT "Aspectos"."ID" AS "Aspecto Normativo ID",
"Aspectos"."Aspecto" AS "Aspecto Normativo",
"Fatores"."ID" AS "Fator Normativo ID",
"Fatores"."Fator" AS "Fator Normativo", "Diagnostico"."Vinculo_Final",
"Fatores_1"."ID" AS "Fator Determinativo ID",
"Fatores_1"."Fator" AS "Fator Determinativo",
"Aspectos_1"."ID" AS "Aspecto Determinativo ID",
"Aspectos_1"."Aspecto" AS "Aspecto Determinativo",
count("Itens"."ID") AS "No Itens",
conta_relatos("Fatores"."ID", "Fatores_1"."ID")
FROM
"Diagnostico"
JOIN ("Aspectos" "Aspectos_1"
JOIN ("Fontes"
JOIN "Itens" ON "Fontes"."ID" = "Itens"."Fonte"
JOIN ("Fatores" "Fatores_1"
JOIN ("Aspectos"
JOIN ("Vinculos"
JOIN "Fatores" ON "Vinculos"."Fator_Normativo" = "Fatores"."ID") ON "Aspectos"."ID" = "Fatores"."Aspecto" AND "Aspectos"."ID" = "Fatores"."Aspecto") ON "Fatores_1"."ID" = "Vinculos"."Fator_Determinativo") ON "Itens"."ID" = "Vinculos"."Item") ON "Aspectos_1"."ID" = "Fatores_1"."Aspecto") ON "Diagnostico"."ID" = "Vinculos"."Diagnostico_ID"
GROUP BY "Aspectos"."ID", "Aspectos"."Aspecto", "Fatores"."ID", "Fatores"."Fator", "Diagnostico"."Vinculo_Final", "Fatores_1"."ID", "Fatores_1"."Fator", "Aspectos_1"."ID", "Aspectos_1"."Aspecto"
ORDER BY "Aspectos"."ID", "Aspectos_1"."ID", "Fatores"."Fator", "Fatores_1"."Fator";