Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id AFAAC9FB4CC for ; Mon, 30 Jul 2007 21:35:22 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 04134-05 for ; Mon, 30 Jul 2007 21:35:14 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id B758D9FB7CF for ; Mon, 30 Jul 2007 21:35:19 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1IFfhe-00027p-OQ for pgsql-sql@postgresql.org; Tue, 31 Jul 2007 02:35:10 +0200 Received: from 77.70.61.39 ([77.70.61.39]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 31 Jul 2007 02:35:10 +0200 Received: from milen by 77.70.61.39 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 31 Jul 2007 02:35:10 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: "Milen A. Radev" Subject: Re: Table-name as parameter to plpgsql Date: Tue, 31 Jul 2007 03:34:59 +0300 Lines: 23 Message-ID: References: <200707302335.16951.andreak@officenet.no> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 77.70.61.39 User-Agent: Thunderbird 2.0.0.5 (Windows/20070716) In-Reply-To: <200707302335.16951.andreak@officenet.no> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.118 tagged_above=0 required=5 tests=AWL=0.650, BAYES_00=-2.599, RCVD_NUMERIC_HELO=2.067 X-Spam-Level: X-Archive-Number: 200707/190 X-Sequence-Number: 28925 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