By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,118 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,118 IT Pros & Developers. It's quick & easy.

How do I get query result(select e.g.) from a dynamic command(EXECUTE)?

P: n/a
Hi,

I want to do a select in dynamic command, something like:

TRIGGER FUNCTION
DECLARE
table_name_suffix text;
temp_result RECORD;
temp_result2 RECORD;

....

BEGIN
--initialization of table_name_suffix(from TG_RELNAME e.g.)
select into temp_result from
''fixed_table_name_prefix''||table_name_suffix where another_table_name =
abc;

--Then I want to use part of the result as part of the table name for my
next query
select into temp_result2 from
''fixed_table_name_prefix''||temp_result.anotherta blename;

END

I know that SELECT INTO doesn't support dynamic command, EXECUTE does. But
if I EXECUTE a select query, how do I get
the select result from it?

Many thanks,

Wei Wang
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Sorry. I just found it in the documentation. FOR-IN-EXECUTE or
OPEN-FOR-EXECUTE.
----- Original Message -----
From: "Wei Wang" <ww***@cam.ac.uk>
To: "pgsql" <pg***********@postgresql.org>
Sent: Thursday, February 19, 2004 11:50 AM
Subject: [GENERAL] How do I get query result(select e.g.) from a dynamic
command(EXECUTE)?

Hi,

I want to do a select in dynamic command, something like:

TRIGGER FUNCTION
DECLARE
table_name_suffix text;
temp_result RECORD;
temp_result2 RECORD;

...

BEGIN
--initialization of table_name_suffix(from TG_RELNAME e.g.)
select into temp_result from
''fixed_table_name_prefix''||table_name_suffix where another_table_name =
abc;

--Then I want to use part of the result as part of the table name for my next query
select into temp_result2 from
''fixed_table_name_prefix''||temp_result.anotherta blename;

END

I know that SELECT INTO doesn't support dynamic command, EXECUTE does. But
if I EXECUTE a select query, how do I get
the select result from it?

Many thanks,

Wei Wang
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 22 '05 #2

P: n/a
On Thursday 19 February 2004 11:50, Wei Wang wrote:
Hi,

I want to do a select in dynamic command, something like:
[snip] I know that SELECT INTO doesn't support dynamic command, EXECUTE does. But
if I EXECUTE a select query, how do I get
the select result from it?

FOR record | row IN EXECUTE text_expression LOOP
statements
END LOOP;

It's in the manuals, but that's about all they say on the subject
--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.