Executing dynamic queries (EXECUTE)

From: "Carla Mello" <carla(dot)mello(at)widesoft(dot)com(dot)br>
To: "Thierry Missimilly" <THIERRY(dot)MISSIMILLY(at)BULL(dot)NET>, Cláudia Morgado <claudia(dot)morgado(at)widesoft(dot)com(dot)br>
Cc: <cmmello(at)wide(dot)com(dot)br>, <pgsql-general(at)postgresql(dot)org>
Subject: Executing dynamic queries (EXECUTE)
Date: 2004-01-26 21:19:23
Message-ID: 00f701c3e452$12a59ac0$16011aac@widesoft.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hello!

I need to execute a dynamic query and capture your result in a integer variable.

I´m using the statement "EXECUTE string", but I don´t obtain to capture the result of dynamic query.

See the example:

======================================================
create or replace function f_population_check() returns bigint as
'
declare
v_tot bigint;
v_query varchar(4000);
v_count integer;
r record;
begin
v_tot:= 0;
for r in select * from pg_tables loop
v_count:= 0;
v_query := ''select count(*) from '' || r.tablename;
v_count:= EXECUTE v_query;
if v_count = 0 then
RAISE NOTICE ''Empty table % '',r.tablename;
end if;
v_tot:= v_tot + 1;
end loop;
return v_tot;
end;
'
language 'plpgsql';

======================================================
ERROR: parse error at or near "$1" at character 18
CONTEXT: PL/pgSQL function "f_population_check" line 11 at assignment

======================================================
Somebody could help me?
Thanks, Carla Mello.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Matthew Jones 2004-01-26 21:40:33 Creating 'global' functions.
Previous Message Andrew Sullivan 2004-01-26 21:11:12 Re: Fwd: Re: [Ossi] New Open Source License: Single Supplier Open Source License