pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedEXECUTE with SELECT INTO variable, or alternatives
3+ messages / 3 participants
[nested] [flat]
* EXECUTE with SELECT INTO variable, or alternatives
@ 2005-09-29 18:16 Mario Splivalo <mario.splivalo@mobart.hr>
2005-09-30 20:59 ` Re: EXECUTE with SELECT INTO variable, or alternatives Thomas F. O'Connell <tfo@sitening.com>
0 siblings, 1 reply; 3+ messages in thread
From: Mario Splivalo @ 2005-09-29 18:16 UTC (permalink / raw)
To: 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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: EXECUTE with SELECT INTO variable, or alternatives
2005-09-29 18:16 EXECUTE with SELECT INTO variable, or alternatives Mario Splivalo <mario.splivalo@mobart.hr>
@ 2005-09-30 20:59 ` Thomas F. O'Connell <tfo@sitening.com>
2005-09-30 23:34 ` Re: EXECUTE with SELECT INTO variable, or alternatives Michael Fuhr <mike@fuhr.org>
0 siblings, 1 reply; 3+ messages in thread
From: Thomas F. O'Connell @ 2005-09-30 20:59 UTC (permalink / raw)
To: mario.splivalo@mobart.hr; +Cc: pgsql-sql
Per the docs:
"The results from SELECT commands are discarded by EXECUTE, and
SELECT INTO is not currently supported within EXECUTE. So there is no
way to extract a result from a dynamically-created SELECT using the
plain EXECUTE command. There are two other ways to do it, however:
one is to use the FOR-IN-EXECUTE loop form described in Section
35.7.4, and the other is to use a cursor with OPEN-FOR-EXECUTE, as
described in Section 35.8.2."
http://www.postgresql.org/docs/8.0/static/plpgsql-
statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN
So you've already hit upon one of your options.
--
Thomas F. O'Connell
Co-Founder, Information Architect
Sitening, LLC
Strategic Open Source: Open Your i™
http://www.sitening.com/
110 30th Avenue North, Suite 6
Nashville, TN 37203-6320
615-469-5150
615-469-5151 (fax)
On Sep 29, 2005, at 1:16 PM, Mario Splivalo wrote:
> 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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: EXECUTE with SELECT INTO variable, or alternatives
2005-09-29 18:16 EXECUTE with SELECT INTO variable, or alternatives Mario Splivalo <mario.splivalo@mobart.hr>
2005-09-30 20:59 ` Re: EXECUTE with SELECT INTO variable, or alternatives Thomas F. O'Connell <tfo@sitening.com>
@ 2005-09-30 23:34 ` Michael Fuhr <mike@fuhr.org>
0 siblings, 0 replies; 3+ messages in thread
From: Michael Fuhr @ 2005-09-30 23:34 UTC (permalink / raw)
To: Thomas F. O'Connell <tfo@sitening.com>; +Cc: mario.splivalo@mobart.hr; pgsql-sql
On Fri, Sep 30, 2005 at 03:59:06PM -0500, Thomas F. O'Connell wrote:
> Per the docs:
>
> "The results from SELECT commands are discarded by EXECUTE, and
> SELECT INTO is not currently supported within EXECUTE. So there is no
> way to extract a result from a dynamically-created SELECT using the
> plain EXECUTE command. There are two other ways to do it, however:
> one is to use the FOR-IN-EXECUTE loop form described in Section
> 35.7.4, and the other is to use a cursor with OPEN-FOR-EXECUTE, as
> described in Section 35.8.2."
8.1 will have EXECUTE ... INTO.
http://developer.postgresql.org/docs/postgres/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-D...
--
Michael Fuhr
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2005-09-30 23:34 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-09-29 18:16 EXECUTE with SELECT INTO variable, or alternatives Mario Splivalo <mario.splivalo@mobart.hr>
2005-09-30 20:59 ` Thomas F. O'Connell <tfo@sitening.com>
2005-09-30 23:34 ` Michael Fuhr <mike@fuhr.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox