pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Carla Mello <carla.mello@widesoft.com.br>
To: pgsql-sql@postgresql.org
Subject: Executing dynamic queries (EXECUTE)
Date: Tue, 27 Jan 2004 13:25:56 -0200
Message-ID: <013d01c3e4e9$dbe16300$16011aac@widesoft.com.br> (raw)

  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.

view thread (3+ messages)  latest in thread

Message-ID: <013d01c3e4e9$dbe16300$16011aac@widesoft.com.br>
Permalink:  ../013d01c3e4e9$dbe16300$16011aac@widesoft.com.br/
Also on:    postgresql.org/message-id/013d01c3e4e9$dbe16300$16011aac@widesoft.com.br

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: carla.mello@widesoft.com.br
  Subject: Re: Executing dynamic queries (EXECUTE)
  In-Reply-To: <013d01c3e4e9$dbe16300$16011aac@widesoft.com.br>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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