Cannot assign ROWTYPE, RECORD variables in PL/pgSQL

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: "Rison, Stuart" <srison(at)rvc(dot)ac(dot)uk>, <pgsql-bugs(at)postgresql(dot)org>
Subject: Cannot assign ROWTYPE, RECORD variables in PL/pgSQL
Date: 2002-11-06 22:27:16
Message-ID: 200211061427.16554.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-sql

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:
=======================================
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 := this_row;

return that_row.first_name;

end;'
language 'plpgsql';
=======================================

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

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

that_record := 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
the source table. While a relatively easy workaround, this behaviour is
annoying and inconsistent. It would be nice to fix in 7.3.1 or 7.4.

Thanks for your attention.

--
-Josh Berkus
Aglio Database Solutions
San Francisco

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Eisentraut 2002-11-06 23:30:00 Re: hi-problem in creating database in postgresql 7.2.2
Previous Message Rison, Stuart 2002-11-06 21:30:22 Re: Copying a rowtype variable.

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleus Mantzios 2002-11-07 07:33:21 Re: [SQL] Problem: Referential Integrity Constraints lost
Previous Message Rison, Stuart 2002-11-06 21:30:22 Re: Copying a rowtype variable.