Re: why VARIADIC functions executed on array input?

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: tjibbe(at)rijpma(dot)org
Cc: PostgreSQL mailing lists <pgsql-general(at)postgresql(dot)org>
Subject: Re: why VARIADIC functions executed on array input?
Date: 2014-02-19 14:40:20
Message-ID: CAFj8pRCbejSPzu=pLy0Ydrzbqr87T+vrYNFdbqYzXu0n-_aYrA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

2014-02-19 15:17 GMT+01:00 Tjibbe <tjibbe(at)rijpma(dot)org>:

> CREATE FUNCTION foo (VARIADIC anyarray) RETURNS void AS $$
> DECLARE
> BEGIN
> END
> $$ LANGUAGE plpgsql;
> SELECT foo (ARRAY[1]);
>
> I would expect an error: Like:
> ERROR: function f3oo(integer[]) does not exist
>
> But I get this error:
> ERROR: could not find array type for data type integer[]
>
> Why VARIADIC functions are found on array input? In my opinion it
> makes no sense and the disadvantage is that overloading with a
> function like: CREATE OR REPLACE FUNCTION foo (anyarray) doesn't
> work.
>

A variadic functions are exception in mechanism, how postgres choose any
specific function. Usually parser try to search function with same name and
most similar parameter types list. Variadic functions works differently -
we try to dynamically prepare parameter list to be able consume values
specified by caller. This mechanism has some corner cases - we are not able
detect all possible ambiguous parameters in creation time, and some times
it raises little bit unclean messages, but generally it works well - but
every enhancing is welcome

Regards

Pavel

>
> Greetings Tjibbe
>
> see example in: http://sqlfiddle.com/#!15/300e8/1
>
>
>
> --
> +31 6 29401726
> tjibbe(at)rijpma(dot)org
> Jacobusstraat 185
> 3012 JM Rotterdam
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dev Kumkar 2014-02-19 14:41:51 UTF-8 collation on Windows?
Previous Message Merlin Moncure 2014-02-19 14:38:00 Re: why VARIADIC functions executed on array input?