Re: [BUGS] SQL Bug

Поиск
Список
Период
Сортировка
От Oleksandr Shulgin
Тема Re: [BUGS] SQL Bug
Дата
Msg-id CACACo5Tst5ajDc_yEZoaFY3xFe9tV4ftqbqac56NHwi=Z6Qncg@mail.gmail.com
обсуждение исходный текст
Ответ на SQL Bug  (Bujji Babu <bujji.babu@heales.com>)
Список pgsql-sql
On Thu, Oct 6, 2016 at 12:22 PM, Bujji Babu <bujji.babu@heales.com> wrote:
>
> Version string:   PostgreSQL 9.5.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4), 64-bit
>  
> Please let me know if anyone knows how to fix this. below query works fine in version 9.4.
>  
>  
> select * from connectby('emp','empid','mgrid','1',0)
> AS t(keyid text, parent_keyid text, level int);
>  
>  
>
> ERROR: invalid return type DETAIL: SQL key field type text does not match return key field type integer. ********** Error ********** ERROR: invalid return type SQL state: 42804 Detail: SQL key field type text does not match return key field type integer.
>  
> CREATE TABLE public.emp
> (
> empid integer NOT NULL,
> name text,
> mgrid integer,
> CONSTRAINT emp_pkey PRIMARY KEY (empid)
> )

Hello,

This is not a bug.

From the documentation at https://www.postgresql.org/docs/9.5/static/tablefunc.html

> The first two output columns are used for the current row's key and its parent row's key; they must match the type of the table's key field.

So, you need to change the type of the first two returned columns to int:

=# select * from connectby('emp','empid','mgrid','1',0) AS t(keyid int, parent_keyid int, level int);
 keyid | parent_keyid | level 
-------+--------------+-------
     1 |              |     0
     2 |            1 |     1
     4 |            2 |     2
     5 |            2 |     2
     3 |            1 |     1
(5 rows)

--
Alex

В списке pgsql-sql по дате отправления:

Предыдущее
От: Heikki Linnakangas
Дата:
Сообщение: Re: [BUGS] SQL Bug
Следующее
От: Bujji Babu
Дата:
Сообщение: Re: [BUGS] SQL Bug