Thread: Schemas not available for pl/pgsql %TYPE....

Schemas not available for pl/pgsql %TYPE....

From
Sean Chittenden
Date:
Call me crazy, but shouldn't the following work?  :~|


CREATE FUNCTION t() RETURNS TEXT AS '
DECLARE
    col_name pg_catalog.pg_attribute.attname%TYPE;
BEGIN
    col_name :=3D ''uga'';
    RETURN col_name;
END;
' LANGUAGE 'plpgsql';
CREATE FUNCTION


SELECT t();
WARNING:  plpgsql: ERROR during compile of t near line 2
ERROR:  Invalid type name 'pg_catalog.pg_attribute.attname % TYPE'


-sc

--=20
Sean Chittenden

Re: Schemas not available for pl/pgsql %TYPE....

From
Tom Lane
Date:
Sean Chittenden <sean@chittenden.org> writes:
> Call me crazy, but shouldn't the following work?  :~|

Sure should.  Want to fix plpgsql's parser?

            regards, tom lane

Re: Schemas not available for pl/pgsql %TYPE....

From
Sean Chittenden
Date:
> Sean Chittenden <sean@chittenden.org> writes:
> > Call me crazy, but shouldn't the following work?  :~|
>
> Sure should.  Want to fix plpgsql's parser?

Why not: I've never been one to avoid strapping on 4tons in rocks and
jumping into the deep end.  ::sigh:: Is it me or does it look like all
of pl/pgsql is schema un-aware (ie, all of the declarations).  -sc

--
Sean Chittenden

Re: Schemas not available for pl/pgsql %TYPE....

From
Tom Lane
Date:
Sean Chittenden <sean@chittenden.org> writes:
> ::sigh:: Is it me or does it look like all
> of pl/pgsql is schema un-aware (ie, all of the declarations).  -sc

Yeah.  The group of routines parse_word, parse_dblword, etc that are
called by the lexer certainly all need work.  There are some
definitional issues to think about, too --- plpgsql presently relies on
the number of names to give it some idea of what to look for, and those
rules are probably all toast now.  Please come up with a sketch of what
you think the behavior should be before you start hacking code.

            regards, tom lane

Re: Schemas not available for pl/pgsql %TYPE....

From
Bruce Momjian
Date:
Tom Lane wrote:
> Sean Chittenden <sean@chittenden.org> writes:
> > ::sigh:: Is it me or does it look like all
> > of pl/pgsql is schema un-aware (ie, all of the declarations).  -sc
>
> Yeah.  The group of routines parse_word, parse_dblword, etc that are
> called by the lexer certainly all need work.  There are some
> definitional issues to think about, too --- plpgsql presently relies on
> the number of names to give it some idea of what to look for, and those
> rules are probably all toast now.  Please come up with a sketch of what
> you think the behavior should be before you start hacking code.

Added to TODO:

            o Make PL/PgSQL %TYPE schema-aware

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: Schemas not available for pl/pgsql %TYPE....

From
Sean Chittenden
Date:
> > ::sigh:: Is it me or does it look like all
> > of pl/pgsql is schema un-aware (ie, all of the declarations).  -sc
>
> Yeah.  The group of routines parse_word, parse_dblword, etc that are
> called by the lexer certainly all need work.  There are some
> definitional issues to think about, too --- plpgsql presently relies
> on the number of names to give it some idea of what to look for, and
> those rules are probably all toast now.  Please come up with a
> sketch of what you think the behavior should be before you start
> hacking code.

Not a problem there.  I walked around the code for a bit, made a few
hacks to see how things are working, and I can tell you strait up that
if you'd like this by 7.3, it won't be happening from me.  <:~) I'm
stretched kinda thin as is and don't think I'll be able to get this
working correctly with time to test by release.  I can send you the
patch I've got for the lexer, but that was chump.  What I was going to
do could be totally wrong, but...

* Change the lexer to recognize schema.table.column%TYPE as a token
  and was going to create parse_tripwordtype() that'd look up the
  table and column in the appropriate schema and would return the
  appropriate type.

If I were lazy, I'd just unshift the schema off of the token and
return what comes back from parse_dblwordtype(), but that doesn't
strike me as correct for something that's performance sensitive.
Beyond doing that, I'm at a loss.  :-/  Thoughts?  -sc

--
Sean Chittenden

Re: Schemas not available for pl/pgsql %TYPE....

From
Joe Conway
Date:
Sean Chittenden wrote:
> Not a problem there.  I walked around the code for a bit, made a few
> hacks to see how things are working, and I can tell you strait up that
> if you'd like this by 7.3, it won't be happening from me.  <:~) I'm
> stretched kinda thin as is and don't think I'll be able to get this
> working correctly with time to test by release.  I can send you the
> patch I've got for the lexer, but that was chump.

If you want to send me what you've done so far, I'll take a look and see
if I can figure it out. I think this is probably a must do item for 7.3.

Any further guidance or thoughts?

Thanks,

Joe