Re: [SQL] Copying a rowtype variable.

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: "Rison, Stuart" <srison(at)rvc(dot)ac(dot)uk>, "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>, "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: [SQL] Copying a rowtype variable.
Date: 2002-11-05 16:55:27
Message-ID: web-1813013@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

Stuart,

> Just doing a bit of PL/PGSQL so my first question is:
>
> 1) should PL/PGSQL questions be posted to the general mailing list,
> the sql
> mailing list or both?

The SQL list is the best place.

> 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.

Another thing to try is, instead of a simple variable assignment,

SELECT current_row INTO previous_row;

... and see if that works. I'll tinker later today; there has to be a
way to do it.

-Josh Berkus

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2002-11-05 16:57:08 Re: log file?
Previous Message Florian Litot 2002-11-05 16:11:48 Re: log file?

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2002-11-05 18:19:15 Re: [GENERAL] Database Design tool
Previous Message Robert Treat 2002-11-05 16:50:03 Re: [GENERAL] Database Design tool