我有这个复杂的查询,其中用户定义的函数conta_relatos()
作为选择语句运行得很好。但是当我尝试使用相同的指令创建视图时它不起作用。Postgres 告诉我“conta_relatos”列有伪类型记录。这个函数,conta_relatos()
返回一个记录类型变量。
编辑添加:
返回类型是前面问题中定义的众所周知的复合类型:
Postgres Function End Loop and return Error
以下是查询:
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";