pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: joe@tanga.com
To: pgsql-bugs@postgresql.org
Subject: BUG #7808: unnest doesn't handle nulls in array of composite types correctly
Date: Mon, 14 Jan 2013 21:11:08 +0000
Message-ID: <E1TurJE-0006Es-TK@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      7808
Logged by:          Joe Van Dyk
Email address:      joe@tanga.com
PostgreSQL version: 9.2.1
Operating system:   OSX
Description:        

RhodiumToad says this is a bug in unnest, but honestly I don't quite
understand it all. 

He said: "if you have an array of composite, then a null element provokes
that error, as opposed to an element all of whose columns are null.
basically, unnest(array[null::g])  breaks, while
unnest(array[row(null,null)::g])  works"

My goal is to remove nulls from an array. The array could be an array of a
composite type.

begin;                                                                      
                       
                                                                            
                       
create table f (id integer);                                                
                       
insert into f values (1), (2);                                              
                       
                                                                            
                       
create table g (id integer, f_id integer);                                  
                       
insert into g values (1, 1);                                                
                       
insert into g values (2, 1);                                                
                       
                                                                            
                       
create function no_nulls(anyarray) returns anyarray as $$                   
                       
  select array(select x from unnest($1) x where not (x is null))            
                       
$$ language sql;                                                            
                       
                                                                            
                       
select f.id, no_nulls(array_agg(g))                                         
                       
from f                                                                      
                       
left join g on g.f_id = f.id                                                
                       
group by f;

                                                                            
                 
Expected Result:                                                            
                       
 id |     array_agg                                                         
                       
----+-------------------                                                    
                       
  1 | {"(1,1)","(2,1)"}                                                     
                       
  2 | {}                                                                    
                       
                                                                            
                       
                                                                            
                       
Getting this error:                                                         
                       
                                                                            
                       
psql:/tmp/n.sql:18: ERROR:  function returning set of rows cannot return
null value                 
CONTEXT:  SQL function "no_nulls" statement 1                               
                       
 



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



view thread (8+ messages)  latest in thread

Message-ID: <E1TurJE-0006Es-TK@wrigleys.postgresql.org>
Permalink:  ../E1TurJE-0006Es-TK@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1TurJE-0006Es-TK@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: joe@tanga.com
  Subject: Re: BUG #7808: unnest doesn't handle nulls in array of composite types correctly
  In-Reply-To: <E1TurJE-0006Es-TK@wrigleys.postgresql.org>
  References: <E1TurJE-0006Es-TK@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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