Re: Problems with plpgsql and FOR loops

From: Bill Moran <wmoran(at)potentialtech(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Problems with plpgsql and FOR loops
Date: 2004-02-21 00:33:25
Message-ID: 4036A755.9040004@potentialtech.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:
> Bill Moran <wmoran(at)potentialtech(dot)com> writes:
>
>>Some of the plpgsql functions I've created work fine on 7.4, but
>>fail on 7.3.4. Specifically, when I use a "FOR var IN select LOOP"
>>loop with a LONG select statement, it works fine on 7.4, but
>>bonks with "missing .. at end of SQL expression" in 7.3.4
>
> That error message suggests that plpgsql thinks the "var" is not
> declared as a record or rowtype variable. I think you should look
> to the variable declaration as the source of the issue, not the FOR
> statement itself. There were some 7.4 fixes associated with
> plpgsql rowtype variables, for instance this one:

Ahh ... this is an interesting twist.

In the cases where I'm having problems, I'm defining a custom type
with CREATE TYPE, because it's the easiest way I can think of to
move the data around.

Assuming:

CREATE TYPE testtype AS ...

Are you suggesting that:

rval testtype%ROWTYPE;

is likely to work around the problem? So far, I've just been
using:

rval testtype;

I'll test this to see what happens.

> 2003-04-27 18:21 tgl
>
> * doc/src/sgml/plpgsql.sgml, src/pl/plpgsql/src/gram.y,
> src/pl/plpgsql/src/pl_comp.c, src/pl/plpgsql/src/plpgsql.h: Fix
> plpgsql so that variables of composite types (rowtypes) can be
> declared without having to write %ROWTYPE. If the declared type of
> a variable is a composite type, it'll be taken to be a row variable
> automatically.
>
> although my recollection is that without %ROWTYPE, 7.3 plpgsql would
> fail on the variable declaration.
>
> regards, tom lane
>

--
Bill Moran
Potential Technologies
http://www.potentialtech.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-02-21 00:43:30 Re: finding out actual tuple size
Previous Message Tom Lane 2004-02-21 00:24:02 Re: Problems with plpgsql and FOR loops