pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Milen A. Radev <milen@radev.net>
To: pgsql-sql@postgresql.org
Subject: Re: Table-name as parameter to plpgsql
Date: Tue, 31 Jul 2007 03:34:59 +0300
Message-ID: <f8m03k$d4m$1@sea.gmane.org> (raw)
In-Reply-To: <200707302335.16951.andreak@officenet.no>
References: <200707302335.16951.andreak@officenet.no>

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-D...).


-- 
Milen A. Radev




view thread (2+ messages)

Message-ID: <f8m03k$d4m$1@sea.gmane.org>
Permalink:  ../f8m03k$d4m$1@sea.gmane.org/
Also on:    postgresql.org/message-id/f8m03k$d4m$1@sea.gmane.org

 · 

reply

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: milen@radev.net
  Subject: Re: Table-name as parameter to plpgsql
  In-Reply-To: <f8m03k$d4m$1@sea.gmane.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