我是SO和postgres的新手,所以请原谅我的无知。尝试使用与本文Find cluster given node in PostgreSQL中的解决方案类似的解决方案在postgres中获取图的集群
唯一的区别是我的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[] overallSQL state: 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 search_graph;发布于 2012-09-19 12:13:06
尝试将递归和非递归项中的SELECT列表转换为varchar。
WITH RECURSIVE search_graph(path, last_profile1, last_profile2) AS (
SELECT ARRAY[id]::varchar[], id::varchar, id::varchar
FROM node WHERE id = '408d6b12-d03e-42c2-a2a7-066b3c060a0b'
UNION ALL
SELECT (sg.path || m.toid || m.fromid)::varchar[], m.fromid::varchar, m.toid::varchar
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 search_graph;https://stackoverflow.com/questions/12488282
复制相似问题