dbTalk Databases Forums  

[BUGS] BUG #1677: Bug in select with Union

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #1677: Bug in select with Union in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Julien Vallet
 
Posts: n/a

Default [BUGS] BUG #1677: Bug in select with Union - 05-23-2005 , 08:07 AM







The following bug has been logged online:

Bug reference: 1677
Logged by: Julien Vallet
Email address: julien.vallet (AT) density-tech (DOT) com
PostgreSQL version: 8.0 & 8.0.3
Operating system: Windows XP
Description: Bug in select with Union
Details:

I think there is a problem with the select statement with Union.

Firstable, I create 3 tables (tuserprofileopp, tprofileopp and
tgroupprofileopp).

CREATE TABLE tuserprofileopp
(
internalkey int8 NOT NULL,
CONSTRAINT tuserprofileopp_pkey PRIMARY KEY (internalkey)
);

CREATE TABLE tprofileopp
(
internalkey int8 NOT NULL,
CONSTRAINT tprofileopp_pkey PRIMARY KEY (internalkey)
);

CREATE TABLE tgroupprofileopp
(
internalkey int8 NOT NULL,
manager_id int8,
CONSTRAINT tgroupprofileopp_pkey PRIMARY KEY (internalkey)
);

Then, I write this request:
select *
from
(
select
internalKey, null as manager_id, 0 as clazz_
from TProfileOPP
union select
internalKey, null as manager_id, 1 as clazz_
from TUserProfileOPP
union select
internalKey, manager_id, 2 as clazz_
from TGroupProfileOPP
)
this_;

The result is "ERROR: UNION types text and bigint cannot be matched"

If I do
"select *
from
(
select
internalKey, null as manager_id, 0 as clazz_
from TProfileOPP
union select
internalKey, manager_id, 2 as clazz_
from TGroupProfileOPP
)
this_;", It works.

Thank you.

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] BUG #1677: Bug in select with Union - 05-23-2005 , 08:56 AM






"Julien Vallet" <julien.vallet (AT) density-tech (DOT) com> writes:
Quote:
The result is "ERROR: UNION types text and bigint cannot be matched"
This is the identical issue reported here:
http://archives.postgresql.org/pgsql...2/msg00008.php
See also this thread:
http://archives.postgresql.org/pgsql...2/msg00693.php

The short answer is that what you wrote is illegal per the SQL spec
(which doesn't allow NULL to be used in ways where a type can't be
ascribed immediately). While we'd like to accept it, we have
not figured out a rule that doesn't break the spec in other ways.
For now I'd recommend casting the NULLs explicitly.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


Reply With Quote
  #3  
Old   
Russell Smith
 
Posts: n/a

Default Re: [BUGS] BUG #1677: Bug in select with Union - 05-24-2005 , 03:57 AM



On Mon, 23 May 2005 11:54 pm, Tom Lane wrote:
Quote:
"Julien Vallet" <julien.vallet (AT) density-tech (DOT) com> writes:
The result is "ERROR: UNION types text and bigint cannot be matched"

This is the identical issue reported here:
http://archives.postgresql.org/pgsql...2/msg00008.php
See also this thread:
http://archives.postgresql.org/pgsql...2/msg00693.php

The short answer is that what you wrote is illegal per the SQL spec
(which doesn't allow NULL to be used in ways where a type can't be
ascribed immediately). While we'd like to accept it, we have
not figured out a rule that doesn't break the spec in other ways.
For now I'd recommend casting the NULLs explicitly.
Can we spit out an error that is slightly more relevant? Maybe print
a warning/error that NULL was used without a type?

Regards

Russell Smith
Quote:
regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.