SQL рекурсивные запросы с использованием массива с числовым типом - PullRequest
0 голосов
/ 24 августа 2018

Я пытаюсь выполнить рекурсивный запрос, чтобы получить кратчайшие пути, где идентификатор должен встречаться только один раз в пути. Вид, который я использую, выглядит следующим образом:

pkp_symmetric(
    personknows numeric(20,0),
    personisknown numeric(20,0),
    creation timestamp)

При работе

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 

Я получаю следующую ошибку:

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

Буду признателен за помощь. С наилучшими пожеланиями.

1 Ответ

0 голосов
/ 24 августа 2018

Работа с ограниченными типами данных в массивах немного сложнее.Кажется, единственный способ заставить это работать - неуклюжий:

select pkp.personknows, pkp.personisknown, array[]::numeric[] || pkp.personknows
...

в нерекурсивной части.

Я понятия не имею, почему array [personknows] :: numeric [] не достигает того же самого.

...