Cannot assign ROWTYPE, RECORD variables in PL/pgSQL - Mailing list pgsql-bugs

From Josh Berkus
Subject Cannot assign ROWTYPE, RECORD variables in PL/pgSQL
Date
Msg-id 200211061427.16554.josh@agliodbs.com
Whole thread Raw
Responses Re: Cannot assign ROWTYPE, RECORD variables in PL/pgSQL  (Neil Conway <neilc@samurai.com>)
List pgsql-bugs
Bug: Cannot assign ROWTYPE, RECORD variables in PL/pgSQL
Affects: PL/pgSQL
Severity:  Annoyance
Priority:  Minor Enhancement
Confirmed On: 7.3beta2, Linux

Given the following function:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
create or replace function rowtype_test ()
returns text as '
declare this_row candidates%rowtype;
    that_row candidates%rowtype;
begin
select * into this_row
from candidates;

that_row :=3D this_row;

return that_row.first_name;

end;'
language 'plpgsql';
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

... it will error out at the assignment "that_row :=3D this_row".

For that matter, any attempt to assign the contents of two ROWTYPE or RECOR=
D=20
variables directly to each other will error out:

that_record :=3D this_record;

SELECT this_row INTO that_row;

SELECT * INTO that_row
FROM this_row;

The only way to populate that_row with a copy of this_row is by re-querying=
=20
the source table.   While a relatively easy workaround, this behaviour is=
=20
annoying and inconsistent.  It would be nice to fix in 7.3.1 or 7.4.

Thanks for your attention.

--=20
-Josh Berkus
 Aglio Database Solutions
 San Francisco

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: like not using indexes in 7.3b5?
Next
From: Stephan Szabo
Date:
Subject: Re: Problem with a sequence being acted on by an on insert