Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 2C443476943 for ; Wed, 6 Nov 2002 16:30:51 -0500 (EST) Received: from cmnt4011.rvc.ac.uk (cmnt4011.rvc.ac.uk [195.195.217.13]) by postgresql.org (Postfix) with ESMTP id 36F37476543 for ; Wed, 6 Nov 2002 16:30:41 -0500 (EST) Received: by cmnt4011.rvc.ac.uk with Internet Mail Service (5.5.2653.19) id ; Wed, 6 Nov 2002 21:30:06 -0000 Message-ID: <6BD8CE460CC6EE40B83DDFCED609F84B964D55@cmnt4008.rvc.ac.uk> From: "Rison, Stuart" To: "''pgsql-sql@postgresql.org' '" Cc: 'Josh Berkus ' Subject: Re: Copying a rowtype variable. Date: Wed, 6 Nov 2002 21:30:22 -0000 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/84 X-Sequence-Number: 10226 >> 2) I am looking for an elegant way of copying a rowtype variable: >> >> eg. >> >> DECLARE >> current_row orf%ROWTYPE; >> previous_row orf%ROWTYPE; >> BEGIN >> >> LOOP >> -- use cursors or FOR SELECT to get values into current_row >> -- now try this: >> >> previous_row = current_row; >> END LOOP; >> END; >> >> Now, as I anticipated, this fails because a rowtype variable is a >> composite >> variable. One working alternative is to do: >> > > I haven't tried this. One thing I notice above is that you're using > the equality operator "=" instead of the assignment operator ":=" . > Usually Postgres lets you slack on this, but it would be worth trying > to see whether that has an effect on the problem. > Fair point. But "previous_row := current_row" doesn't work either. > Another thing to try is, instead of a simple variable assignment > > SELECT current_row INTO previous_row; > > ... and see if that works. Well, I had high hopes for that one... but it didn't work either! > I'll tinker later today; there has to be a way to do it. I'd definitely appreciate further suggestions, but thanks all the same for you help. I have a feeling that you might have to write a PL function to perform the operation... but I haven't really thought about it! Stuart.