SQL Bug

Started by Bujji Babuover 9 years ago7 messagesbugs
Jump to latest
#1Bujji Babu
bujji.babu@heales.com

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)
)
insert into emp(empid,mgrid,name)
values(1,0,'emp1');
insert into emp(empid,mgrid,name)
values(2,1,'emp1');
insert into emp(empid,mgrid,name)
values(3,1,'emp1');
insert into emp(empid,mgrid,name)
values(4,2,'emp1');
insert into emp(empid,mgrid,name)
values(5,2,'emp1');

Thanks,
M.Bujji Babu

Thanks&Regards,
M.Bujji Babu.

#2Bujji Babu
bujji.babu@heales.com
In reply to: Bujji Babu (#1)
Re: SQL Bug

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.

schema Backup file attached.
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)
)
insert into emp(empid,mgrid,name)
values(1,0,'emp1');
insert into emp(empid,mgrid,name)
values(2,1,'emp1');
insert into emp(empid,mgrid,name)
values(3,1,'emp1');
insert into emp(empid,mgrid,name)
values(4,2,'emp1');
insert into emp(empid,mgrid,name)
values(5,2,'emp1');

Thanks&Regards,
M.Bujji Babu.

Attachments:

test.pgsql.bakapplication/x-trash; name=test.pgsql.bakDownload
#3Shulgin, Oleksandr
oleksandr.shulgin@zalando.de
In reply to: Bujji Babu (#1)
Re: SQL Bug

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

#4Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Bujji Babu (#1)
Re: [BUGS] SQL Bug

On 10/06/2016 01:22 PM, Bujji Babu 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.

Try:

select * from connectby('emp','empid','mgrid','1','0')
AS t(keyid integer, parent_keyid integer, level int);

connectby() was made more strict about the datatypes matching in 9.5.
See commit 37507962c3d2123b0f21c50d6172fd0b1e059fe7.

- Heikki

--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

#5Bujji Babu
bujji.babu@heales.com
In reply to: Heikki Linnakangas (#4)
Re: [BUGS] SQL Bug

Dear Heikki,

Still same error msg.

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.

Thanks&Regards,
M.Bujji Babu.

----- Original Message -----
From: "Heikki Linnakangas" <hlinnaka@iki.fi>
To: "Bujji Babu" <bujji.babu@heales.com>, pgsql-bugs@postgresql.org, pgsql-sql@postgresql.org
Sent: Thursday, 6 October, 2016 11:44:51 AM
Subject: Re: [BUGS] SQL Bug

On 10/06/2016 01:22 PM, Bujji Babu 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.

Try:

select * from connectby('emp','empid','mgrid','1','0')
AS t(keyid integer, parent_keyid integer, level int);

connectby() was made more strict about the datatypes matching in 9.5.
See commit 37507962c3d2123b0f21c50d6172fd0b1e059fe7.

- Heikki

--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

#6Heikki Linnakangas
heikki.linnakangas@enterprisedb.com
In reply to: Bujji Babu (#5)
Re: SQL Bug

On 10/06/2016 01:59 PM, Bujji Babu wrote:

Dear Heikki,

Still same error msg.

select * from connectby('emp','empid','mgrid','1','0')
AS t(keyid text, parent_keyid text, level int);

That's not what I typed. The keyid and parent_keyid columns need to be
integers, not text, like in the table.

- Heikki

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#7Bujji Babu
bujji.babu@heales.com
In reply to: Heikki Linnakangas (#6)
Re: [BUGS] SQL Bug

Dear Heikki,

It works.

Thanks&Regards,
M.Bujji Babu.

----- Original Message -----
From: "Heikki Linnakangas" <hlinnaka@iki.fi>
To: "Bujji Babu" <bujji.babu@heales.com>
Cc: pgsql-bugs@postgresql.org, pgsql-sql@postgresql.org
Sent: Thursday, 6 October, 2016 12:07:27 PM
Subject: Re: [BUGS] SQL Bug

On 10/06/2016 01:59 PM, Bujji Babu wrote:

Dear Heikki,

Still same error msg.

select * from connectby('emp','empid','mgrid','1','0')
AS t(keyid text, parent_keyid text, level int);

That's not what I typed. The keyid and parent_keyid columns need to be
integers, not text, like in the table.

- Heikki

--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql