pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Sabin Coanda <sabin.coanda@deuromedia.ro>
Cc: pgsql-sql@postgresql.org
Subject: Re: array_to_string
Date: Tue, 27 Mar 2007 16:45:01 +0100
Message-ID: <46093BFD.8060007@archonet.com> (raw)
In-Reply-To: <21430.1175009744@sss.pgh.pa.us>
References: <euaelf$28f8$1@news.hub.org>
	<20090.1175006990@sss.pgh.pa.us>
	<46093147.6000209@archonet.com>
	<21430.1175009744@sss.pgh.pa.us>

Tom Lane wrote:
> Richard Huxton <dev@archonet.com> writes:
>> Tom Lane wrote:
>>> "Sabin Coanda" <sabin.coanda@deuromedia.ro> writes:
>>>> I used the function array_to_string, and I found it ignores NULL values, 
>>>> e.g. array_to_string( 'ARRAY[1,NULL,3]', ',' ) returns '1,3'.
>>> Do you have a better idea?
> 
>> If you're being strict it should presumably return NULL for the whole 
>> string. Or you'd need a "coalesce-to-this" parameter.
> 
> If the whole array is NULL it would return NULL, but that seems
> unhelpful for a single element being NULL ...

It's the least surprising choice though. You'd expect array_to_string() 
to be a loop doing something like:
   output = output || connector || arr[i]
Of course this will produce NULL if any of the inputs are NULL. Now that 
might be unhelpful, but that's NULL for you.

All you're doing is (presumably) adding a hidden test to the loop where 
Sabin seemed to expect COALESCE(arr[i],<something>). I'm not sure either 
is better across the board.

The problem comes with what <something> should be. You're either looking 
at a third parameter or perhaps more cleanly you need a 
coalesce_array(ARRAY,VAL) function which produces an output array where 
all the null elemts are replaced by VAL.

-- 
   Richard Huxton
   Archonet Ltd



view thread (6+ messages)  latest in thread

Message-ID: <46093BFD.8060007@archonet.com>
Permalink:  ../46093BFD.8060007@archonet.com/
Also on:    postgresql.org/message-id/46093BFD.8060007@archonet.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com, tgl@sss.pgh.pa.us, sabin.coanda@deuromedia.ro
  Subject: Re: array_to_string
  In-Reply-To: <46093BFD.8060007@archonet.com>

* 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