Re: Table-name as parameter to plpgsql

From: "Milen A(dot) Radev" <milen(at)radev(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Table-name as parameter to plpgsql
Date: 2007-07-31 00:34:59
Message-ID: f8m03k$d4m$1@sea.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Andreas Joseph Krogh написа:
> The following function failes to compile:
>
> CREATE OR REPLACE FUNCTION test_func(p_table_name VARCHAR) RETURNS VOID AS $$
> BEGIN
> INSERT INTO p_table_name(some_field) VALUES('some_value');
> END;
> $$ LANGUAGE plpgsql;
>
> Gives:
> ERROR: syntax error at or near "$1"
> LINE 1: INSERT INTO $1 (some_field) VALUES('some_value')
>
> Any hints on how to use function-parameters as table-names like I'm trying to
> above?
>

Use EXECUTE
(http://www.postgresql.org/docs/current/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN).

--
Milen A. Radev

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ronald Rojas 2007-07-31 04:19:47 alter table table add column
Previous Message Scott Marlowe 2007-07-30 22:20:07 Re: Connection Limit