Thread: plpgsql and Schemas

plpgsql and Schemas

From
Rod Taylor
Date:
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?





Re: plpgsql and Schemas

From
Rod Taylor
Date:
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'.



Re: plpgsql and Schemas

From
Tom Lane
Date:
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


Re: plpgsql and Schemas

From
Rod Taylor
Date:
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.



Re: plpgsql and Schemas

From
Peter Eisentraut
Date:
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