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@gmx.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@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers