plpgsql and Schemas

Started by Rod Taylorover 23 years ago5 messages
#1Rod Taylor
rbt@zort.ca

I've been running a few functions within schema's. It's annoying that
everything needs to be qualified as it doesn't allow the functions to be
moved very easily.

Would it be appropriate for the function to have it's own schema as
pre-pended onto the user path while in the users function?

#2Rod Taylor
rbt@zort.ca
In reply to: Rod Taylor (#1)
Re: plpgsql and Schemas

On Sun, 2002-07-14 at 20:36, Rod Taylor wrote:

I've been running a few functions within schema's. It's annoying that
everything needs to be qualified as it doesn't allow the functions to be
moved very easily.

Would it be appropriate for the function to have it's own schema as
pre-pended onto the user path while in the users function?

Thats a weird way of saying 'prepended to the path during function
execution'.

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Rod Taylor (#1)
Re: plpgsql and Schemas

Rod Taylor <rbt@zort.ca> writes:

I've been running a few functions within schema's. It's annoying that
everything needs to be qualified as it doesn't allow the functions to be
moved very easily.
Would it be appropriate for the function to have it's own schema as
pre-pended onto the user path while in the users function?

Hmm. I can think of examples where you wouldn't want that (because
the function *should* see the caller's namespace) about as easily
as cases where you would.

If a function wants to access "its own schema", why shouldn't it
use qualified references?

regards, tom lane

#4Rod Taylor
rbt@zort.ca
In reply to: Tom Lane (#3)
Re: plpgsql and Schemas

On Sun, 2002-07-14 at 21:19, Tom Lane wrote:

Rod Taylor <rbt@zort.ca> writes:

I've been running a few functions within schema's. It's annoying that
everything needs to be qualified as it doesn't allow the functions to be
moved very easily.
Would it be appropriate for the function to have it's own schema as
pre-pended onto the user path while in the users function?

Hmm. I can think of examples where you wouldn't want that (because
the function *should* see the caller's namespace) about as easily
as cases where you would.

If a function wants to access "its own schema", why shouldn't it
use qualified references?

I was thinking of the effort put into pg_dump to prevent over qualifying
references in order to allow the user to move stuff easily. It's not a
big deal, but does prevent this ability with functions.

#5Peter Eisentraut
peter_e@gmx.net
In reply to: Rod Taylor (#1)
Re: plpgsql and Schemas

Rod Taylor writes:

I've been running a few functions within schema's. It's annoying that
everything needs to be qualified as it doesn't allow the functions to be
moved very easily.

Would it be appropriate for the function to have it's own schema as
pre-pended onto the user path while in the users function?

The SQL standard has rules on how the effective schema path during a
function execution is determined. In a nutshell, it allows you to specify
the path as an attribute of the containing schema. E.g.,

CREATE SCHEMA foo PATH here, there;

I haven't thought this through, but you might want to think about it.

--
Peter Eisentraut peter_e@gmx.net