Re: array_to_string bug?

Lists: pgsql-hackers
From: David Fetter <david(at)fetter(dot)org>
To: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: array_to_string bug?
Date: 2009-11-12 15:55:13
Message-ID: 20091112155513.GB26790@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Folks,

Here's expected behavior:

davidfetter(at)postgres=# SELECT array(values(1),(null));
?column?
──────────
{1,NULL}
(1 row)

The next one is just plain unexpected. Either it's a bug, or it needs
more documentation in the function description in the docs, \df+
output, etc.

davidfetter(at)postgres=# SELECT array_to_string(array(values(1),(null)),'');
array_to_string
─────────────────
1
(1 row)

I would have expected it to come out as NULL.

What say?

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Fetter <david(at)fetter(dot)org>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: array_to_string bug?
Date: 2009-11-12 16:20:26
Message-ID: 4234.1258042826@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

David Fetter <david(at)fetter(dot)org> writes:
> The next one is just plain unexpected.

array_to_string ignores null elements. What do you think it should do
with them?

regards, tom lane


From: David Fetter <david(at)fetter(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: array_to_string bug?
Date: 2009-11-12 18:06:14
Message-ID: 20091112180614.GA13922@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Nov 12, 2009 at 11:20:26AM -0500, Tom Lane wrote:
> David Fetter <david(at)fetter(dot)org> writes:
> > The next one is just plain unexpected.
>
> array_to_string ignores null elements. What do you think it should
> do with them?

It should concatenate them, i.e. return a NULL if the array includes
any NULLs. That, or it should explain that it doesn't do that because
there's nothing in the docs that would indicate this behavior.

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: David Fetter <david(at)fetter(dot)org>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: array_to_string bug?
Date: 2009-11-12 18:28:17
Message-ID: 4AFC53C1.5050009@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> David Fetter <david(at)fetter(dot)org> writes:
>
>> The next one is just plain unexpected.
>>
>
> array_to_string ignores null elements. What do you think it should do
> with them?
>
> regards, tom lane
>
>
This seems somewhat related to the long-running discussion from back in
February-April regarding string_to_array with empty input which faded
away somewhere around here:
http://archives.postgresql.org/pgsql-hackers/2009-04/msg00363.php. At
the time the decision was to defer any decision to after 8.4.

Perhaps there is a solution which can address both cases - ideally one
which would, to the extent practical, allow string_to_array to be the
inverse of array_to_string. This could be particularly useful when
dealing with clients that don't know how to directly deal with
PostgreSQL arrays but which can generally easily deal with strings.

Although it might cause a fair amount of backward-compatibility trouble,
the string representation could either use NULL to represent a null
element as is allowed in other contexts or require that empty-string
elements be represented as "" to differentiate ,"", (empty-string
element) from ,, (null element).

Cheers,
Steve


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, David Fetter <david(at)fetter(dot)org>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: array_to_string bug?
Date: 2009-11-12 18:33:41
Message-ID: 603c8f070911121033n7f741473kbcdd1ce7089b0ef3@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Nov 12, 2009 at 1:28 PM, Steve Crawford
<scrawford(at)pinpointresearch(dot)com> wrote:
> Although it might cause a fair amount of backward-compatibility trouble, the
> string representation could either use NULL to represent a null element as
> is allowed in other contexts or require that empty-string elements be
> represented as "" to differentiate ,"", (empty-string element) from ,, (null
> element).

That would cause a substantial amount of grief to people who might not
want that behavior, though. I use these functions for creating
human-readable output, not for serialization. Simple, predictable
behavior is very important.

...Robert


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Steve Crawford <scrawford(at)pinpointresearch(dot)com>, David Fetter <david(at)fetter(dot)org>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: array_to_string bug?
Date: 2009-11-12 18:46:42
Message-ID: 14471.1258051602@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> On Thu, Nov 12, 2009 at 1:28 PM, Steve Crawford
> <scrawford(at)pinpointresearch(dot)com> wrote:
>> Although it might cause a fair amount of backward-compatibility trouble, the
>> string representation could either use NULL to represent a null element as
>> is allowed in other contexts or require that empty-string elements be
>> represented as "" to differentiate ,"", (empty-string element) from ,, (null
>> element).

> That would cause a substantial amount of grief to people who might not
> want that behavior, though. I use these functions for creating
> human-readable output, not for serialization. Simple, predictable
> behavior is very important.

I agree --- we don't want to start introducing quoting rules into
array_to_string. I think the viable alternatives are the current
behavior, or treating a NULL element as if it were an empty string.
David's idea that the entire output should go to NULL might be sane
from a strict semantics point of view, but it also seems to make the
function just about entirely useless in practice.

regards, tom lane


From: David Fetter <david(at)fetter(dot)org>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Steve Crawford <scrawford(at)pinpointresearch(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: array_to_string bug?
Date: 2009-11-12 18:46:47
Message-ID: 20091112184647.GB13922@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Nov 12, 2009 at 01:33:41PM -0500, Robert Haas wrote:
> On Thu, Nov 12, 2009 at 1:28 PM, Steve Crawford
> <scrawford(at)pinpointresearch(dot)com> wrote:
> > Although it might cause a fair amount of backward-compatibility
> > trouble, the string representation could either use NULL to
> > represent a null element as is allowed in other contexts or
> > require that empty-string elements be represented as "" to
> > differentiate ,"", (empty-string element) from ,, (null element).
>
> That would cause a substantial amount of grief to people who might
> not want that behavior, though. I use these functions for creating
> human-readable output, not for serialization. Simple, predictable
> behavior is very important.

My question boils down to, "why is this string concatenation different
from all other string concatenations?"

For now, the answer can be, "it behaves differently with respect to
NULLs," and we just document this. We can later decide whether this
behavior should change.

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


From: "David E(dot) Wheeler" <david(at)kineticode(dot)com>
To: David Fetter <david(at)fetter(dot)org>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: array_to_string bug?
Date: 2009-11-12 19:46:54
Message-ID: A70C97DD-3E22-4998-B9A2-BE63C17F1550@kineticode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Nov 12, 2009, at 10:46 AM, David Fetter wrote:

> My question boils down to, "why is this string concatenation different
> from all other string concatenations?"

Does it have something to do with afikoman?

David


From: David Fetter <david(at)fetter(dot)org>
To: "David E(dot) Wheeler" <david(at)kineticode(dot)com>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: array_to_string bug?
Date: 2009-11-12 19:52:32
Message-ID: 20091112195232.GA8505@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Nov 12, 2009 at 11:46:54AM -0800, David Wheeler wrote:
> On Nov 12, 2009, at 10:46 AM, David Fetter wrote:
>
> > My question boils down to, "why is this string concatenation
> > different from all other string concatenations?"
>
> Does it have something to do with afikoman?

I was wondering who'd comment on that first ;)

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate