pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #8696: Type-checking seems to fail on UNIONs with arrays
3+ messages / 3 participants
[nested] [flat]
* BUG #8696: Type-checking seems to fail on UNIONs with arrays
@ 2013-12-23 00:47 jp.deplaix@gmail.com
0 siblings, 1 reply; 3+ messages in thread
From: jp.deplaix@gmail.com @ 2013-12-23 00:47 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 8696
Logged by: Jacques-Pascal Deplaix
Email address: jp.deplaix@gmail.com
PostgreSQL version: 9.3.2
Operating system: Linux
Description:
Hi,
I'm wondering why the following examples works:
(SELECT NULL AS test)
UNION
(SELECT array_agg(t.name) AS test FROM foo AS t)
;
(SELECT NULL AS test)
UNION
(SELECT array_agg(t.name) AS test FROM foo AS t)
UNION
(SELECT NULL AS test)
;
but this one:
(SELECT NULL AS test)
UNION
(SELECT NULL AS test)
UNION
(SELECT array_agg(t.name) AS test FROM foo AS t)
;
fails with:
ERROR: UNION types text and text[] cannot be matched
Is it (as I suppose) a bug or a well known limitation ?
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #8696: Type-checking seems to fail on UNIONs with arrays
@ 2013-12-23 01:21 Vik Fearing <vik.fearing@dalibo.com>
parent: jp.deplaix@gmail.com
0 siblings, 1 reply; 3+ messages in thread
From: Vik Fearing @ 2013-12-23 01:21 UTC (permalink / raw)
To: jp.deplaix@gmail.com; pgsql-bugs
On 12/23/2013 01:47 AM, jp.deplaix@gmail.com wrote:
> (SELECT NULL AS test)
> UNION
> (SELECT NULL AS test)
> UNION
> (SELECT array_agg(t.name) AS test FROM foo AS t)
> ;
>
>
> fails with:
> ERROR: UNION types text and text[] cannot be matched
>
>
> Is it (as I suppose) a bug or a well known limitation ?
It's a well known limitation (I knew what was coming before I read it),
but I can't seem to find the right keywords to dig up a reference about
it at the moment.
It has nothing to do with arrays, but the fact that you have *two*
unknown types before a known one.
To wit:
vik=# select null union select null union select 1;
ERROR: UNION types text and integer cannot be matched
LINE 1: select null union select null union select 1;
The workaround is to provide the type in either the first or second
union-ed query:
vik=# select null::integer union select null union select 1;
int4
----
1
(2 rows)
vik=# select null union select null::integer union select 1;
?column?
--------
1
(2 rows)
PS: Interesting that the column name changed with those two queries...
--
Vik
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #8696: Type-checking seems to fail on UNIONs with arrays
@ 2013-12-23 14:33 Michael Paquier <michael.paquier@gmail.com>
parent: Vik Fearing <vik.fearing@dalibo.com>
0 siblings, 0 replies; 3+ messages in thread
From: Michael Paquier @ 2013-12-23 14:33 UTC (permalink / raw)
To: Vik Fearing <vik.fearing@dalibo.com>; +Cc: jp.deplaix@gmail.com; pgsql-bugs
On Mon, Dec 23, 2013 at 10:21 AM, Vik Fearing <vik.fearing@dalibo.com> wrote:
> On 12/23/2013 01:47 AM, jp.deplaix@gmail.com wrote:
>> (SELECT NULL AS test)
>> UNION
>> (SELECT NULL AS test)
>> UNION
>> (SELECT array_agg(t.name) AS test FROM foo AS t)
>> ;
>>
>>
>> fails with:
>> ERROR: UNION types text and text[] cannot be matched
>>
>>
>> Is it (as I suppose) a bug or a well known limitation ?
>
> It's a well known limitation (I knew what was coming before I read it),
> but I can't seem to find the right keywords to dig up a reference about
> it at the moment.
>
> It has nothing to do with arrays, but the fact that you have *two*
> unknown types before a known one.
>
> To wit:
>
> vik=# select null union select null union select 1;
> ERROR: UNION types text and integer cannot be matched
> LINE 1: select null union select null union select 1;
>
> The workaround is to provide the type in either the first or second
> union-ed query:
>
> vik=# select null::integer union select null union select 1;
> int4
> ----
>
> 1
> (2 rows)
>
> vik=# select null union select null::integer union select 1;
> ?column?
> --------
>
> 1
> (2 rows)
>
> PS: Interesting that the column name changed with those two queries...
Yep, this is because a cast simply calls a dedicated function for the
conversion, and this function name is used:
http://www.postgresql.org/docs/devel/static/sql-expressions.html#SQL-SYNTAX-TYPE-CASTS
Regards,
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2013-12-23 14:33 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-12-23 00:47 BUG #8696: Type-checking seems to fail on UNIONs with arrays jp.deplaix@gmail.com
2013-12-23 01:21 ` Vik Fearing <vik.fearing@dalibo.com>
2013-12-23 14:33 ` Michael Paquier <michael.paquier@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox