Re: Table-name as parameter to plpgsql - Mailing list pgsql-sql

From Milen A. Radev
Subject Re: Table-name as parameter to plpgsql
Date
Msg-id f8m03k$d4m$1@sea.gmane.org
Whole thread Raw
In response to Table-name as parameter to plpgsql  (Andreas Joseph Krogh <andreak@officenet.no>)
List 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



pgsql-sql by date:

Previous
From: "Scott Marlowe"
Date:
Subject: Re: Connection Limit
Next
From: Ronald Rojas
Date:
Subject: alter table table add column