variable scooping

From: ody quraviharto <odyyudah(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: variable scooping
Date: 2006-01-30 02:01:37
Message-ID: 5a3d805c0601291801j7de16f2eq15a4cd9698dbc7e4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

hi all,
I'm a newbie in postgresql. I've tried to make function but having
trouble in variable scooping.
here is the code in plpgsql:

"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". I
thought variable 'tbl_name' was not recognized. Why ?
Please need some help here.
Thx very much.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Daniel CAUNE 2006-01-30 03:40:46 Re: Function with default value?
Previous Message Daniel CAUNE 2006-01-29 20:15:21 Function with default value?