From: Michael Fuhr <mike@fuhr.org>
To: ody quraviharto <odyyudah@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: variable scooping
Date: Sun, 29 Jan 2006 21:24:24 -0700
Message-ID: <20060130042424.GA56410@winnie.fuhr.org> (raw)
In-Reply-To: <5a3d805c0601291801j7de16f2eq15a4cd9698dbc7e4@mail.gmail.com>
References: <5a3d805c0601291801j7de16f2eq15a4cd9698dbc7e4@mail.gmail.com>
On Mon, Jan 30, 2006 at 09:01:37AM +0700, ody quraviharto wrote:
> "declare tbl_name varchar:='tbl_A';
> begin
> if exists(select 1 from pg_tables where tablename=tbl_name) then
> select count(*) from tbl_name;
> end if;
> end"
>
> the message was: syntax error in $1 in "select count(*) from $1".
You'll need to use EXECUTE for this query; see "Executing Dynamic
Commands" in the PL/pgSQL documentation. Here's the link for 8.1
(but use the documentation for whatever version you're running):
http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-...
--
Michael Fuhr
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: mike@fuhr.org, odyyudah@gmail.com
Subject: Re: variable scooping
In-Reply-To: <20060130042424.GA56410@winnie.fuhr.org>
* 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