Re: proposal: fix corner use case of variadic fuctions usage

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Vik Reykja <vikreykja(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: fix corner use case of variadic fuctions usage
Date: 2013-01-23 12:13:18
Message-ID: CAFj8pRAytWYKAT1uJXn2=MGdYqEkzDTj+KTtduX6cam+KDaoeQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

2013/1/23 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:
> 2013/1/23 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>> Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
>>> what should be result of concat(variadic NULL::int[])
>>> I enabled this use case, but what should be result?
>>
>> I think there are two somewhat defensible theories:
>>
>> (1) punt, and return NULL overall. So in this case the variadic
>> function would act as if it were STRICT. That seems a bit weird though
>> if the function is not strict otherwise.
>>
>> (2) Treat the NULL as if it were a zero-length array, giving rise to
>> zero ordinary parameters. This could be problematic if the function
>> can't cope very well with zero parameters ... but on the other hand,
>> if it can't do so, then what will it do with VARIADIC '{}'::int[] ?
>
> This is repeated question - how much is NULL ~ '{}'
>
> There is only one precedent, I think
>
> postgres=# select '>>>' || array_to_string('{}'::int[], '') || '<<<';
> ?column?
> ----------
> >>><<<
> (1 row)
>
> postgres=# select '>>>' || array_to_string(NULL::int[], '') || '<<<';
> ?column?
> ----------
>
> (1 row)
>
> but this function is STRICT - so there is no precedent :(

next related example

CREATE OR REPLACE FUNCTION public.myleast(VARIADIC integer[])
RETURNS integer
LANGUAGE sql
AS $function$
select min(v) from unnest($1) g(v)
$function$

postgres=# select myleast(variadic array[]::int[]) is null;
?column?
----------
t
(1 row)

postgres=# select myleast(variadic null::int[]) is null;
?column?
----------
t
(1 row)

so it is close to Tom (2)

concat(VARIADIC NULL::int[]) and concat(VARIADIC '{}'::int[]) should
returns NULL

it is little bit strange, but probably it is most valid

Regards

Pavel

>
>>
>> I lean a little bit towards (2) but it's definitely a judgment call.
>> Anybody have any other arguments one way or the other?
>>
>
>
>
>> regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Farber 2013-01-23 12:13:46 Re: Sending several commands simultaneously to PostgreSQL 8.4
Previous Message Gavan Schneider 2013-01-23 09:24:31 Re: Yet Another Timestamp Question: Time Defaults

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2013-01-23 12:14:13 Re: logical changeset generation v4
Previous Message Etsuro Fujita 2013-01-23 12:05:52 Re: Review : Add hooks for pre- and post-processor executables for COPY and \copy