X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 7144A9F944D for ; Sun, 14 May 2006 13:13:04 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 97279-09 for ; Sun, 14 May 2006 13:12:55 -0300 (ADT) X-Greylist: delayed 00:27:01.850741 by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 0A99E9FA4E1 for ; Sun, 14 May 2006 13:12:51 -0300 (ADT) Received: from achille.dalibo.net (achille.dalibo.net [212.85.153.230]) by svr4.postgresql.org (Postfix) with ESMTP id 503BF5B25CD for ; Sun, 14 May 2006 15:45:48 +0000 (GMT) Received: from localhost (localhost.localdomain [127.0.0.1]) by achille.dalibo.net (Postfix) with ESMTP id C8DF215F61; Sun, 14 May 2006 17:33:22 +0200 (CEST) Received: from achille.dalibo.net ([127.0.0.1]) by localhost (achille [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 07880-04; Sun, 14 May 2006 17:33:22 +0200 (CEST) Received: from [192.168.0.1] (maison.argudo.org [81.56.190.65]) by achille.dalibo.net (Postfix) with ESMTP id D437815F5E; Sun, 14 May 2006 17:33:20 +0200 (CEST) Message-ID: <44675072.8030104@argudo.org> Date: Sun, 14 May 2006 17:44:50 +0200 From: Jean-Paul Argudo User-Agent: Thunderbird 1.5.0.2 (X11/20060501) MIME-Version: 1.0 To: Scott Yohonn Cc: "pgsql-sql@postgresql.org" Subject: Re: PL/PGSQL - How to pass in variables? References: In-Reply-To: X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at dalibo.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/106 X-Sequence-Number: 25137 Hi Scott, You'll have to execute dynamic SQL (see doc chapter "36.6.5. Executing Dynamic Commands") for your function to work: CREATE FUNCTION get_table_count(tablename text) RETURNS integer AS $$ DECLARE --tablename ALIAS FOR $1; rowcount INTEGER; BEGIN execute 'SELECT count(*) FROM '||tablename into rowcount; return rowcount; END; $$ LANGUAGE 'plpgsql'; select get_table_count('bar'); get_table_count ----------------- 3 (1 row) Cheers, -- Jean-Paul Argudo www.PostgreSQLFr.org www.dalibo.com