Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fAUH9om96346 for ; Fri, 30 Nov 2001 12:09:50 -0500 (EST) (envelope-from josh@agliodbs.com) Received: from [209.10.40.250] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.4.7) with HTTP id 517138; Fri, 30 Nov 2001 09:09:53 -0800 From: "Josh Berkus" Subject: Re: variables in procedures To: =?ISO-8859-1?Q?Mart=EDn_Marqu=E9s?= , pgsql-sql@postgresql.org X-Mailer: CommuniGate Pro Web Mailer v.3.4.7 Date: Fri, 30 Nov 2001 09:09:53 -0800 Message-ID: In-Reply-To: <20011130134344.BED7EFA61@bugs.unl.edu.ar> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Archive-Number: 200111/439 X-Sequence-Number: 5820 Martin, > How can I distinguish between the name and the value of a variable? You need to name your variables something *different* from your column names. Otherwise, you will get unexpected errors. A practice I usually follow is prefixing my column-substitiution variables with "v_". This allows me, and the PL/pgSQL parser, to keep the variables straight from the columns. I also need to fix your procedure in a couple of places. Thus: CREATE FUNCTION test(VARCHAR) RETURNS INTEGER AS ' DECLARE v_col1 ALIAS FOR $1; v_result INT; BEGIN select col1 INTO v_result from tab where col1 = v_col1; RETURN v_result; END; ´ LANGUAGE 'plpgsql'; Other SQL-procedural languages (e.g. Transact-SQL) force you to prefix your variables with special characters. In PL/pgSQL, it's up to you to maintain consistency. -Josh Berkus ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco