Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 608749FA2F8 for ; Mon, 30 Jul 2007 19:00:50 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 98827-03 for ; Mon, 30 Jul 2007 19:00:47 -0300 (ADT) X-Greylist: delayed 00:25:05.0844 by SQLgrey-1.7.5 Received: from ns1.officenet.no (ns1.officenet.no [193.212.174.3]) by postgresql.org (Postfix) with ESMTP id 31F219FA2B7 for ; Mon, 30 Jul 2007 19:00:47 -0300 (ADT) Received: from [84.48.119.79] (helo=krogh-laptop.local) by ns1.officenet.no with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.62) (envelope-from ) id 1IFctm-0004im-8K for pgsql-sql@postgresql.org; Mon, 30 Jul 2007 23:35:39 +0200 From: Andreas Joseph Krogh Organization: OfficeNet AS To: "sql pgsql" Subject: Table-name as parameter to plpgsql Date: Mon, 30 Jul 2007 23:35:16 +0200 User-Agent: KMail/1.9.7 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200707302335.16951.andreak@officenet.no> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200707/188 X-Sequence-Number: 28923 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=20 above? =2D-=20 Andreas Joseph Krogh Senior Software Developer / Manager =2D-----------------------+---------------------------------------------+ OfficeNet AS | The most difficult thing in the world is to | Karenslyst All=C3=A9 11 | know how to do a thing and to watch | PO. Box 529 Sk=C3=B8yen | somebody else doing it wrong, without | 0214 Oslo | comment. | NORWAY | | Tlf: +47 24 15 38 90 | | =46ax: +47 24 15 38 91 | | Mobile: +47 909 56 963 | | =2D-----------------------+---------------------------------------------+