Re: Copying a rowtype variable.

From: Jean-Luc Lachance <jllachan(at)nsd(dot)ca>
To: "Rison, Stuart" <srison(at)rvc(dot)ac(dot)uk>
Cc: "''pgsql-sql(at)postgresql(dot)org' '" <pgsql-sql(at)postgresql(dot)org>, "'Josh Berkus '" <josh(at)agliodbs(dot)com>
Subject: Re: Copying a rowtype variable.
Date: 2002-11-07 16:28:55
Message-ID: 3DCA94C7.4EA02207@nsd.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-sql

I would personnaly like this feature (assigning a composite from another
similar composite) to be added to PLPGSQL. Another nice feature would be
to able to insert a composite into a table without have to name all
atributes.

Just my $.02

"Rison, Stuart" wrote:
>
> >> 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.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Stephan Szabo 2002-11-07 16:50:32 Re: Problem with a sequence being acted on by an on insert
Previous Message Tom Lane 2002-11-07 14:57:35 Re: like not using indexes in 7.3b5?

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleus Mantzios 2002-11-07 16:38:06 Re: [SQL] Problem: Referential Integrity Constraints lost
Previous Message Richard Huxton 2002-11-07 16:13:21 Re: PLpgSQL FOR IN EXECUTE question