Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about dynamic query

Status
Not open for further replies.

thedumbkid

Programmer
May 13, 2003
9
US
I have another question :)

It's about dynamic query...
Is it possible to use a dynamic query in pl/pgsql function to update a variable?

I am trying to do something like the following:

create function myfunction(varchar) returns int4 as '
declare
v_table_name alias for $1;

v_num int4;
begin
execute ''select into v_num count(*) from '' || v_table_name;
end;' language 'plpgsql';
 
nevermind I found the answer...
I can use

rec record;

and then to assign:

for rec in execute ''select count(*) from '' || v_table_name || '' as count'' loop
v_num := rec.count;
end loop;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top