Re: how to pass the function caller's parameter to inside the function. syntax error at or near "$1"

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: leaf_yxj <leaf_yxj(at)163(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: how to pass the function caller's parameter to inside the function. syntax error at or near "$1"
Date: 2012-03-28 16:36:36
Message-ID: CAHyXU0z2aRejtWK+Nzj9o7UG_5U2cHwDzwi4kv3ZAaRu32GP+A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Mar 28, 2012 at 11:18 AM, leaf_yxj <leaf_yxj(at)163(dot)com> wrote:
> I want to create a function which use to truncate the table specified by the
> caller. I very confused how postgresql pass this parameter into the function
> :
>
> as a superuser to execute :
> 1)
> create or replace function d() returns void as $$
> analyze;
> $$ language sql;
>
>
> ----- this works when i issue select d()
>
> 2) this doesn't work
>
> create or replace function v(text) returns void as $$
> analyze $1;
> $$ language sql;
>
>  why???? and how to correct it?
>
>
> I tried another function for insert
>
> 1) this works.
>
> create or replace function insert_f(integer) returns void as $$
> insert into t1 values($1);
> $$ language sql;
>
> ----this works when i issue select insert_f(20);
>
> 2) this doesn't work.
>
> create or replace function insert_f(text,integer) returns void as $$
> insert into $1 values($2);
> $$ language sql;
>
> ---- it failed to create the function and give me error : syntax error at or
> near "$1".
>
> Please help.

you're not allowed to parameterize table names. workaround is
plpgsql's EXECUTE.

merlin

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message leaf_yxj 2012-03-28 16:38:09 Re: how postgresql passes the parameter to the function. syntax error near or at "$1".
Previous Message Pavel Stehule 2012-03-28 16:25:27 Re: how postgresql passes the parameter to the function. syntax error near or at "$1".