What about SELECT INTO in EXECUTE

Started by ivanabout 23 years ago5 messagesgeneral
Jump to latest
#1ivan
iv@psycho.pl

when in plpgsql i do EXECUTE ''SELECT INTO foo 4 ''; its not implemented
yet, so when ?

#2Richard Huxton
dev@archonet.com
In reply to: ivan (#1)
Re: What about SELECT INTO in EXECUTE

On Tuesday 04 Mar 2003 8:30 pm, Ivan wrote:

when in plpgsql i do EXECUTE ''SELECT INTO foo 4 ''; its not implemented
yet, so when ?

I don't think this is valid SQL - should it not be "SELECT 4 INTO foo"?
--
Richard Huxton

#3ivan
iv@psycho.pl
In reply to: Richard Huxton (#2)
Re: What about SELECT INTO in EXECUTE

but its not SQL error but just in plpgsql ,
SELECT INTO same_var sth from table;
I can not write EXECUTE ''SELECT INTO same_var sth from table;'';
because SELECT INTO not work with EXECUTE , so what can i do else ?

On Wed, 5 Mar 2003, Richard Huxton wrote:

Show quoted text

On Tuesday 04 Mar 2003 8:30 pm, Ivan wrote:

when in plpgsql i do EXECUTE ''SELECT INTO foo 4 ''; its not implemented
yet, so when ?

I don't think this is valid SQL - should it not be "SELECT 4 INTO foo"?
--
Richard Huxton

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

#4Patrick Fiche
patrick.fiche@aqsacom.com
In reply to: ivan (#3)
Re: What about SELECT INTO in EXECUTE

I guess one solution is to insert into a temporary table in the EXECUTE
statement...
Then execute a SQL query (without EXECUTE) to get the value into the
variable.
I use to do like that with MS SQL Server as there is no other solution...

Hope it helps

----------------------------------------------------------------------------
---------------
Patrick Fiche
email : patrick.fiche@aqsacom.com
t�l : 01 69 29 36 18
----------------------------------------------------------------------------
---------------

-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org]On Behalf Of Ivan
Sent: Wednesday, March 05, 2003 6:11 PM
To: Richard Huxton
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] What about SELECT INTO in EXECUTE

but its not SQL error but just in plpgsql ,
SELECT INTO same_var sth from table;
I can not write EXECUTE ''SELECT INTO same_var sth from table;'';
because SELECT INTO not work with EXECUTE , so what can i do else ?

On Wed, 5 Mar 2003, Richard Huxton wrote:

On Tuesday 04 Mar 2003 8:30 pm, Ivan wrote:

when in plpgsql i do EXECUTE ''SELECT INTO foo 4 ''; its not implemented
yet, so when ?

I don't think this is valid SQL - should it not be "SELECT 4 INTO foo"?
--
Richard Huxton

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

#5Richard Huxton
dev@archonet.com
In reply to: ivan (#3)
Re: What about SELECT INTO in EXECUTE

On Wednesday 05 Mar 2003 5:10 pm, Ivan wrote:

but its not SQL error but just in plpgsql ,
SELECT INTO same_var sth from table;
I can not write EXECUTE ''SELECT INTO same_var sth from table;'';
because SELECT INTO not work with EXECUTE , so what can i do else ?

Ah, sorry, I see what you're trying to do now.

You're quite right, the SELECT INTO <plpgsql-variable> construct only works
within plpgsql, whereas EXECUTE runs standard SQL.

The solution is to use the FOR ... IN ... EXECUTE loop structure (even if you
only want one row) - see the manual section on plpgsql control structures
(programmers guide) for details. This is a known limitation of the EXECUTE
command and is mentioned in the relevant section, but perhaps not clearly
enough.

HTH

--
Richard Huxton