Thread: Use of %ROWTYPE in plpgsql function declarations

Use of %ROWTYPE in plpgsql function declarations

From
"Karl O. Pinc"
Date:
FYI, FWIW.

Speaking of documentation, it's none too clear that
%ROWTYPE does not seem to work when declaring plpgsql
functions.  (pg 8.0.3  I looked at the release notes
and didn't see anything fixed in newer versions.)

So, either the docs are broken, postgres is broken, or
I'm not reading things right/understanding.  (Or maybe
declaring arguments is new enough that it just does not
work yet.)

babase_copy=# create temp table bar (id int, logic boolean);
CREATE TABLE
babase_copy=# create function baz (arg bar%ROWTYPE) returns void
language 'plpgsql' as $$ begin  return; end; $$;
ERROR:  syntax error at or near "%" at character 29
LINE 1: create function baz (arg bar%ROWTYPE) returns void language ...
                                     ^
babase_copy=# create function baz (arg bar) returns void language
'plpgsql' as $$ begin  return ; end ; $$;
CREATE FUNCTION

Regards,

Karl <kop@meme.com>
Free Software:  "You don't pay back, you pay forward."
                  -- Robert A. Heinlein


Re: Use of %ROWTYPE in plpgsql function declarations

From
Tom Lane
Date:
"Karl O. Pinc" <kop@meme.com> writes:
> Speaking of documentation, it's none too clear that
> %ROWTYPE does not seem to work when declaring plpgsql
> functions.

There is noplace that claims that it does.  Perhaps you
are looking for %TYPE?

            regards, tom lane

Re: Use of %ROWTYPE in plpgsql function declarations

From
"Karl O. Pinc"
Date:
On 12/03/2005 11:31:34 PM, Tom Lane wrote:
> "Karl O. Pinc" <kop@meme.com> writes:
> > Speaking of documentation, it's none too clear that
> > %ROWTYPE does not seem to work when declaring plpgsql
> > functions.
>
> There is noplace that claims that it does.  Perhaps you
> are looking for %TYPE?

Nope.  I saw this:
----<snip>-----
36.4.3. Row Types
...
  Parameters to a function can be composite types (complete table
rows). In that case, the corresponding identifier $n will be a row
variable, and fields can be selected from it, for example $1.user_id.
----<snip>-----

and figured that if it was a row variable I could/should declare it
as such when defining the function.  It just seemed a little wierd
not to have the %ROWTYPE because AFIK you need it when declaring
in plpgsql's DECLARE and otherwise the function argument declarations
look like DECLARE declarations.

No biggie.  Figured I'd throw it out there (to keep me away
from my real work.  ;)

Karl <kop@meme.com>
Free Software:  "You don't pay back, you pay forward."
                  -- Robert A. Heinlein


Re: Use of %ROWTYPE in plpgsql function declarations

From
Tom Lane
Date:
"Karl O. Pinc" <kop@meme.com> writes:
> ...  It just seemed a little wierd
> not to have the %ROWTYPE because AFIK you need it when declaring
> in plpgsql's DECLARE

No, you don't, as 36.4.3 says perfectly clearly.  %ROWTYPE is an
Oracle-ism that we support inside plpgsql, but not elsewhere.

            regards, tom lane