Skip site navigation (1) Skip section navigation (2)

Re: Cannot assign ROWTYPE, RECORD variables in PL/pgSQL

From: Neil Conway <neilc(at)samurai(dot)com>
To: josh(at)agliodbs(dot)com
Cc: "Rison, Stuart" <srison(at)rvc(dot)ac(dot)uk>, <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: Cannot assign ROWTYPE, RECORD variables in PL/pgSQL
Date: 2002-11-07 21:56:35
Message-ID: 87u1itcacs.fsf@mailbox.samurai.com (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-sql
Josh Berkus <josh(at)agliodbs(dot)com> writes:
> 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".

So we'd want a deep copy, right?

> The only way to populate that_row with a copy of this_row is by re-querying 
> the source table.

Well, you can also iterate through the fields of this_row and assign
them to that_row manually -- of course, that's not much better.

> While a relatively easy workaround, this behaviour is annoying and
> inconsistent.  It would be nice to fix in 7.3.1 or 7.4.

Unless anyone sees a problem with this, I'll work on this. I
definately think it's inappropriate for 7.3.1 though.

Cheers,

Neil

-- 
Neil Conway <neilc(at)samurai(dot)com> || PGP Key ID: DB3C29FC


In response to

Responses

pgsql-bugs by date

Next:From: Tom LaneDate: 2002-11-07 22:14:43
Subject: Re: pg_ctl is fragile
Previous:From: Neil ConwayDate: 2002-11-07 21:36:07
Subject: pg_ctl is fragile

pgsql-sql by date

Next:From: Josh BerkusDate: 2002-11-07 22:57:09
Subject: Re: Cannot assign ROWTYPE, RECORD variables in PL/pgSQL
Previous:From: Josh BerkusDate: 2002-11-07 21:30:20
Subject: Re: PLpgSQL FOR IN EXECUTE question

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group