Re: multiple CREATE FUNCTION AS items for PLs

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: multiple CREATE FUNCTION AS items for PLs
Date: 2012-12-16 09:20:53
Message-ID: CAFj8pRBVK2s6_qK5a6hTmqBLA-N1Oz8Gx-PWQ+YeJwK_4YD5LQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

I understand to motivation, but proposed syntax is not too intuitive and robust

can you do it in one function and call import only in first call?

Regards

Pavel

2012/12/16 Peter Eisentraut <peter_e(at)gmx(dot)net>:
> I'm going to use PL/Python as an example, but I would also like to know
> if this could be applicable to other languages.
>
> When you do
>
> CREATE FUNCTION foo(...) ... LANGUAGE plpythonu
> AS $$
> source code here
> $$;
>
> it internally creates a "source file" that contains
>
> ---
> def __plpython_procedure_foo_12345():
> source code here
> ---
>
> It would be useful to be able to do something like this instead:
>
> ---
> some code here
>
> def __plpython_procedure_foo_12345():
> some more code here
> ---
>
> This would especially be useful for placing imports into the first part.
> While you can have them in the function definition, that means they are
> executed every time the function is called, which makes it much slower.
> Also, future imports are not possible this way.
>
> CREATE FUNCTION already supports multiple AS items. Currently, multiple
> AS items are rejected for all languages but C. I'd imagine lifting that
> restriction and leaving it up to the validator to check it. Then any
> language can accept two AS items if it wants and paste them together in
> whichever way it needs. (The probin/prosrc naming will then become more
> obsolete, but it's perhaps not worth changing anything about that.)
>
> So in practice this might look like this:
>
> CREATE FUNCTION foo(...) ... LANGUAGE plpythonu
> AS $$
> import x
> import y
> $$,
> $$
> real code here
> $$;
>
> Comments?
>
>
>
>
> --
> 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2012-12-16 09:40:42 Re: Set visibility map bit after HOT prune
Previous Message Pavan Deolasee 2012-12-16 08:04:39 Re: Makefiles don't seem to remember to rebuild everything anymore