Re: NULLs in array_cat vs array || array

Lists: pgsql-hackers
From: Thom Brown <thom(at)linux(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: NULLs in array_cat vs array || array
Date: 2011-02-15 21:37:21
Message-ID: AANLkTikeJMQY9aELpbQVWPqoeToDnGi6uW3=F8cm_D6G@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi all,

I assumed array_cat would behave similarly to array || array, but it
appears not when it comes to NULLs. Shouldn't these have identical
functionality? The attached patch makes it so, although it would
break existing code.

Would such a change have any knock-on effect, or cause inconsistency
with other functions?

Thanks

Thom

--
Thom Brown
Twitter: @darkixion
IRC (freenode): dark_ixion
Registered Linux user: #516935

Attachment Content-Type Size
array_cat_nulls.patch application/octet-stream 874 bytes

From: Cédric Villemain <cedric(dot)villemain(dot)debian(at)gmail(dot)com>
To: Thom Brown <thom(at)linux(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: NULLs in array_cat vs array || array
Date: 2011-02-15 21:46:09
Message-ID: AANLkTinX0AmpYWr0j1hutgftxaFDbObx+K8OT3o0K1D5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2011/2/15 Thom Brown <thom(at)linux(dot)com>:
> Hi all,
>
> I assumed array_cat would behave similarly to array || array, but it
> appears not when it comes to NULLs.  Shouldn't these have identical
> functionality?  The attached patch makes it so, although it would
> break existing code.

There is bugreport and todo entry for that if it helps:

http://archives.postgresql.org/pgsql-bugs/2008-11/msg00032.php

>
> Would such a change have any knock-on effect, or cause inconsistency
> with other functions?
>
> Thanks
>
> Thom
>
> --
> Thom Brown
> Twitter: @darkixion
> IRC (freenode): dark_ixion
> Registered Linux user: #516935
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>
>

--
Cédric Villemain               2ndQuadrant
http://2ndQuadrant.fr/     PostgreSQL : Expertise, Formation et Support


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Thom Brown <thom(at)linux(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: NULLs in array_cat vs array || array
Date: 2011-02-15 21:47:42
Message-ID: 11693.1297806462@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Thom Brown <thom(at)linux(dot)com> writes:
> I assumed array_cat would behave similarly to array || array, but it
> appears not when it comes to NULLs. Shouldn't these have identical
> functionality? The attached patch makes it so, although it would
> break existing code.

That patch is the hard way: the right change would be to remove the code
altogether and mark the function strict in pg_proc. However, the fact
that it's not like that already shows that we went out of our way to
make it so. I don't think we should undo that decision just because
somebody submits a patch to do so.

Also, so far as I can see array_cat *is* ||, so I'm not sure what
discrepancy in behavior you're on about.

regards, tom lane


From: Thom Brown <thom(at)linux(dot)com>
To: Cédric Villemain <cedric(dot)villemain(dot)debian(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: NULLs in array_cat vs array || array
Date: 2011-02-15 21:50:00
Message-ID: AANLkTi=Q1SJwMvAy6cZ7jF=d1YL5=R=AQoGOS-mf0BmJ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 15 February 2011 21:46, Cédric Villemain
<cedric(dot)villemain(dot)debian(at)gmail(dot)com> wrote:
> 2011/2/15 Thom Brown <thom(at)linux(dot)com>:
>> Hi all,
>>
>> I assumed array_cat would behave similarly to array || array, but it
>> appears not when it comes to NULLs.  Shouldn't these have identical
>> functionality?  The attached patch makes it so, although it would
>> break existing code.
>
> There is bugreport and todo entry for that if it helps:
>
> http://archives.postgresql.org/pgsql-bugs/2008-11/msg00032.php

Ah, I see. More to it than meets the eye. My bad.

--
Thom Brown
Twitter: @darkixion
IRC (freenode): dark_ixion
Registered Linux user: #516935


From: Thom Brown <thom(at)linux(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: NULLs in array_cat vs array || array
Date: 2011-02-15 21:58:20
Message-ID: AANLkTi=dwugPR4OkKbcYHQ44ak40k0KWKvpaBdnJhLkh@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 15 February 2011 21:47, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Also, so far as I can see array_cat *is* ||, so I'm not sure what
> discrepancy in behavior you're on about.

You've confused me now. I had a case where I replaced || with , and
surrounded it with array_cat, and the result differed, and now I can't
recreate it. I think I should get an early night.

--
Thom Brown
Twitter: @darkixion
IRC (freenode): dark_ixion
Registered Linux user: #516935