Re: SQL Bug

From: Oleksandr Shulgin <oleksandr(dot)shulgin(at)zalando(dot)de>
To: Bujji Babu <bujji(dot)babu(at)heales(dot)com>
Cc: Pg Bugs <pgsql-bugs(at)postgresql(dot)org>, pgsql-sql(at)postgresql(dot)org
Subject: Re: SQL Bug
Date: 2016-10-06 10:44:46
Message-ID: CACACo5Tst5ajDc_yEZoaFY3xFe9tV4ftqbqac56NHwi=Z6Qncg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-sql

On Thu, Oct 6, 2016 at 12:22 PM, Bujji Babu <bujji(dot)babu(at)heales(dot)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

In response to

  • SQL Bug at 2016-10-06 10:22:23 from Bujji Babu

Browse pgsql-bugs by date

  From Date Subject
Next Message Heikki Linnakangas 2016-10-06 10:44:51 Re: [BUGS] SQL Bug
Previous Message Bujji Babu 2016-10-06 10:23:12 Re: SQL Bug

Browse pgsql-sql by date

  From Date Subject
Next Message Heikki Linnakangas 2016-10-06 10:44:51 Re: [BUGS] SQL Bug
Previous Message Bujji Babu 2016-10-06 10:23:12 Re: SQL Bug