X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id E8BED9DCC37 for ; Fri, 17 Mar 2006 13:52:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 03029-10 for ; Fri, 17 Mar 2006 13:52:55 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from perseverance.encs.concordia.ca (perseverance-96.encs.concordia.ca [132.205.96.94]) by postgresql.org (Postfix) with ESMTP id ECBF29DCBA3 for ; Fri, 17 Mar 2006 13:52:53 -0400 (AST) Received: from [132.205.47.205] (IDENT:emilu@curacao.encs.concordia.ca [132.205.47.205]) by perseverance.encs.concordia.ca (8.12.11/8.12.11) with ESMTP id k2HHqrUO024798 for ; Fri, 17 Mar 2006 12:52:53 -0500 Message-ID: <441AF775.7060006@encs.concordia.ca> Date: Fri, 17 Mar 2006 12:52:53 -0500 From: Emi Lu Reply-To: emilu@encs.concordia.ca User-Agent: Mozilla Thunderbird 1.0.7 (X11/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: in PlPgSQL function, how to use variable in a "select ... into .. where " query Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.43 on perseverance.encs.concordia.ca at 2006/03/17 12:52:53 EST X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.135 required=5 tests=[AWL=0.135, UPPERCASE_25_50=0] X-Spam-Score: 0.135 X-Spam-Level: X-Archive-Number: 200603/251 X-Sequence-Number: 24597 Hello, In pl/pgsql (postgresql 8.01), how to use variables in select .. into .. command CREATE OR REPLACE FUNCTION test(VARCHAR) RETURNS VARCHAR AS $$ DECLARE var1 ALIAS FOR $1; cm_tableName tableA.col1%TYPE; T1 VARCHAR := 'sourceTable'; query_value VARCHAR ; BEGIN SELECT col2 INTO cm_tableName FROM T1 WHERE col1 = var1 ; EXECUTE query_value; RETURN cm_tableName; END; $$ language 'plpgsql' IMMUTABLE STRICT; select test('abc'); Failed. Also, tried "SELECT col2 INTO cm_tableName FROM || T1 WHERE col1 = || var1 " and "SELECT col2 INTO cm_tableName FROM || T1 || WHERE col1 = || var1" Failed as well. T1 and var1 both are variables, may I how to use variables in a "select ... into " query please? Thanks a lot, Ying