首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用数值类型的数组进行SQL递归查询

使用数值类型的数组进行SQL递归查询
EN

Stack Overflow用户
提问于 2018-08-24 19:14:19
回答 1查看 286关注 0票数 0

我尝试运行一个递归查询来获得最短路径,其中id最多在路径中出现一次。我使用的视图如下所示:

代码语言:javascript
复制
pkp_symmetric(
    personknows numeric(20,0),
    personisknown numeric(20,0),
    creation timestamp)

运行时

代码语言:javascript
复制
with recursive temp(persStart, persNext, pfad, tiefe, pcycle ) 
            as 
            (select pkp.personknows, pkp.personIsKnown, array[pkp.personKnows], 1, false 
            from pkp_symmetric pkp--pidstart, pidstart, pidstart
            union all 
            select p.personknows, p.personisknown, t.pfad|| t.persNext, t.tiefe + 1, p.personknows = ANY(t.pfad)  
            from pkp_symmetric p join  temp t 
            on p.personknows = t.persNext where not pcycle )

            select * from temp t 

我得到以下错误:

代码语言:javascript
复制
SQL Error [42804]: ERROR: recursive query "temp" column 3 has type numeric(20,0)[] in non-recursive term but type numeric[] overall
  Hinweis: Cast the output of the non-recursive term to the correct type.
  Position: 119
  SQL Error [42804]: ERROR: recursive query "temp" column 3 has type numeric(20,0)[] in non-recursive term but type numeric[] overall
  Hinweis: Cast the output of the non-recursive term to the correct type.
  Position: 119
    SQL Error [42804]: ERROR: recursive query "temp" column 3 has type numeric(20,0)[] in non-recursive term but type numeric[] overall
  Hinweis: Cast the output of the non-recursive term to the correct type.
  Position: 119
      SQL Error [42804]: ERROR: recursive query "temp" column 3 has type numeric(20,0)[] in non-recursive term but type numeric[] overall
  Hinweis: Cast the output of the non-recursive term to the correct type.
  Position: 119
        ERROR: recursive query "temp" column 3 has type numeric(20,0)[] in non-recursive term but type numeric[] overall
  Hinweis: Cast the output of the non-recursive term to the correct type.
  Position: 119
        ERROR: recursive query "temp" column 3 has type numeric(20,0)[] in non-recursive term but type numeric[] overall
  Hinweis: Cast the output of the non-recursive term to the correct type.
  Position: 119

如果能得到一些帮助我将不胜感激。诚挚的问候。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-24 19:16:18

在数组中处理有界数据类型有点棘手。这似乎是让它工作的唯一方法是一个笨拙的:

代码语言:javascript
复制
select pkp.personknows, pkp.personisknown, array[]::numeric[] || pkp.personknows
...

在非递归部分。

我不知道为什么arraypersonknows::numeric[]不能实现同样的功能。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52003262

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档