EXECUTE with SELECT INTO variable, or alternatives - Mailing list pgsql-sql

From Mario Splivalo
Subject EXECUTE with SELECT INTO variable, or alternatives
Date
Msg-id 1128017805.9061.5.camel@localhost.localdomain
Whole thread Raw
Responses Re: EXECUTE with SELECT INTO variable, or alternatives
List 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''
LOOPmyVar := 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



pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Selecting count of details along with details columns
Next
From: Axel Rau
Date:
Subject: Re: Selecting count of details along with details columns