小编tod*_*odd的帖子

Postgres CTE:非递归项中的类型字符变化(255)[]但整体上类型字符变化[]

我是SO和postgres的新手所以请原谅我的无知.尝试使用类似于本文中的解决方案在postgres中获取图表的集群在PostgreSQL中查找集群给定节点

唯一的区别是我的id是一个UUID,我使用varchar(255)来存储这个id

当我尝试运行查询时,我收到以下错误(但不知道如何投射):

ERROR: recursive query "search_graph" column 1 has type character varying(255)[] in non-recursive term but type character varying[] overall
Run Code Online (Sandbox Code Playgroud)

SQL状态:42804提示:将非递归项的输出强制转换为正确的类型.性格:81

我的代码(与上一篇文章基本相同):

WITH RECURSIVE search_graph(path, last_profile1, last_profile2) AS (
SELECT ARRAY[id], id, id
FROM node WHERE id = '408d6b12-d03e-42c2-a2a7-066b3c060a0b'
UNION ALL
SELECT sg.path || m.toid || m.fromid, m.fromid, m.toid
FROM search_graph sg
JOIN rel m
ON (m.fromid = sg.last_profile2 AND NOT sg.path @> ARRAY[m.toid]) 
   OR (m.toid = sg.last_profile1 AND NOT sg.path @> ARRAY[m.fromid])
)

 SELECT DISTINCT unnest(path) FROM …
Run Code Online (Sandbox Code Playgroud)

postgresql graph-theory common-table-expression

11
推荐指数
1
解决办法
6309
查看次数