EXECUTE with SELECT INTO variable, or alternatives

From: Mario Splivalo <mario(dot)splivalo(at)mobart(dot)hr>
To: pgsql-sql(at)postgresql(dot)org
Subject: EXECUTE with SELECT INTO variable, or alternatives
Date: 2005-09-29 18:16:44
Message-ID: 1128017805.9061.5.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I can assign a value to a variable in several ways:

myVar := (SELECT col FROM table WHERE somecondition...)
myVar := col FROM table WHERE somecondtition...
SELECT col INTO myVar FROM table WHERE somecondition

How do I do any of the above using EXECUTE? I need to be able to assign
the value to a variable, a value returned by a querry on a temporary
table.

So far I have found workaround like this:

myRec record;

FOR rec IN EXECUTE ''SELECT col FROM table WHERE somecondition''
LOOP
myVar := rec
END LOOP

Obviously, the above SELECT query returns only one row. Still, if is
realy inconvinient to have FOR...LOOP...END LOOP construct for assigning
the value to a variable 'read' from the temporary table.

Mario

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Axel Rau 2005-09-29 19:08:15 Re: Selecting count of details along with details columns
Previous Message Richard Huxton 2005-09-29 10:03:51 Re: Selecting count of details along with details columns