From: | "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "Pgsql Hackers" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: proposal: generic function, constructor function |
Date: | 2008-01-18 21:34:45 |
Message-ID: | 162867790801181334u6ad8ecefl616917df0e127dad@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 18/01/2008, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> writes:
> > I propose two kinds of functions:
>
> > a) generic functions - this function allows any params without any
> > implicit casting (it can implemented only in C language).
>
> Can't you do that already with ANYELEMENT, or at the worst ANY?
Anyelement is related with casting to common type.
postgres=# create or replace function fx(anyelement, anyelement)
returns text as $$begin return 'ahoj'; end; $$ language plpgsql;
CREATE FUNCTION
postgres=# select fx(1,'a');
ERROR: invalid input syntax for integer: "a"
postgres=# select fx(1,'a');
I would to have independent parameters and move type checking to
function. Then I don't need register function exactly and then I can
have different numbers of arguments. It's similar like C varargs
functions so now I cannot effectively implement printf function,
because all parameters are casted to varchar.
Using any is broken. ?
postgres=# create or replace function fx1(any) returns text as $$begin
return 'ahoj'; end; $$ language plpgsql;
ERROR: syntax error at or near "any"
LINE 1: create or replace function fx1(any) returns text as $$begin ...
^
>
> > It allows unspecified number of params
> > without parser changes.
>
> Why is that a good idea (and if you think it won't take parser changes,
> you're wrong)?
Of course. Implementation needs some changes in parser. But new
generic function doesn't need it. With generic functions some xml
functions could exists outside parser. And it's simple tool for
constructors.
>
> > Limits: only one function with specified name can exists in schema.
>
> This is why it's a bad idea. Please note that the unique index on
> pg_proc cannot enforce that, even if we wanted such a restriction.
>
we can use partial unique index, if it is possible - I didn't test it.
Regards
Pavel Stehule
> regards, tom lane
>
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2008-01-18 21:40:03 | Re: Recent pg_regress changes break testing under SELinux |
Previous Message | Tom Lane | 2008-01-18 20:59:59 | Re: proposal: generic function, constructor function |