I am working on a recurcive query and I work on a guid stocked in a varchar(90) column. But I got an cast type exception from pgAdmin when working with Postgres 11.1
I'm stuck and I don't know what could i do to solve this, if any one can help me.
https://docs.postgresql.fr/8.4/queries-with.html
with recursive sousSujet(typerefin,coderefin,typerefout,coderefout,type,profondeur,chemin, boucle) as (
SELECT p.typerefin, p.coderefin, p.typerefout , p.coderefout , p.type,1, ARRAY[p.coderefout]::varchar(90)[] ,false
FROM relation p
WHERE p.coderefin='2019094070' and p.typerefin='PROJET'
--union all
union
SELECT p.typerefin, p.coderefin, pr.typerefout, pr.coderefout, p.type ,pr.profondeur+1,
--chemin || pr.coderefout,pr.coderefout = ANY(pr.chemin)
chemin::varchar(90)[] || pr.coderefout,pr.coderefout = ANY(pr.chemin::varchar(90)[])
FROM relation p,sousSujet pr
-- WHERE p.coderefin = pr.coderefout
WHERE p.coderefin = pr.coderefout AND NOT pr.boucle and pr.profondeur < 10
)
SELECT typerefin,coderefin,typerefout,coderefout,type,profondeur
FROM sousSujet
order by coderefout limit 20
ERROR: ERREUR: dans la requête récursive « soussujet », la colonne 7 a le type character varying(90)[] dans le terme non
récursif mais le type global character varying[]
LINE 3: ...oderefin, p.typerefout , p.coderefout , p.type,1, ARRAY[p.co...
^
HINT: Convertit la sortie du terme non récursif dans le bon type.