Curious unnest behavior - Mailing list pgsql-general

From Jeff Trout
Subject Curious unnest behavior
Date
Msg-id 9A0BFC9D-1983-45CC-94AA-F84DAE8B9B36@torgo.978.org
Whole thread Raw
Responses Re: Curious unnest behavior  (Patrick Krecker <patrick@judicata.com>)
Re: Curious unnest behavior  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-general
I just ran into an interesting thing with unnest and empty arrays.

create table x (
    a int,
    b int[]
);

insert into x(a,b) values (1, '{}');
insert into x(a,b) values (1, '{}');
insert into x(a,b) values (1, '{}');

select a, b from x;
select a, unnest(b) from x;

insert into x(a,b) values (2, '{5,6}');
select a, unnest(b) from x;

drop table x;

gives me:
CREATE TABLE
INSERT 0 1
INSERT 0 1
INSERT 0 1
 a | b
---+----
 1 | {}
 1 | {}
 1 | {}
(3 rows)

 a | unnest
---+--------
(0 rows)

INSERT 0 1
 a | unnest
---+--------
 2 |      5
 2 |      6
(2 rows)

DROP TABLE

I can understand the likely reasoning behind the behavior but perhaps a note in the documentation about it might be of
usefor others that may get bit by this functionality.  (especially given the structure of the query, had I been doing
select* from unnest(arr) that would be more intuitive, but given the query structure of select with no where the
resultscan be surprising.) 

thanks

--
Jeff Trout <jeff@jefftrout.com>




pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: alter default privileges problem
Next
From: Jose Martinez
Date:
Subject: Unable to reload postgresql.conf without restarting