X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 29AC99DCBE1; Mon, 6 Mar 2006 14:30:50 -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 76096-07; Mon, 6 Mar 2006 14:30:49 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 306619DCB57; Mon, 6 Mar 2006 14:30:46 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k26IUh7Z085243 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 6 Mar 2006 11:30:45 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k26IUhMP014209; Mon, 6 Mar 2006 11:30:43 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k26IUgmL014208; Mon, 6 Mar 2006 11:30:42 -0700 (MST) (envelope-from mfuhr) Date: Mon, 6 Mar 2006 11:30:42 -0700 From: Michael Fuhr To: Emil Rachovsky Cc: "pgsql-general@postgresql.org" , "pgsql-sql@postgresql.org" Subject: Re: Syntax error in Execute statement Message-ID: <20060306183042.GA14001@winnie.fuhr.org> References: <20060306152158.81224.qmail@web54312.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060306152158.81224.qmail@web54312.mail.yahoo.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.122 required=5 tests=[AWL=0.122] X-Spam-Score: 0.122 X-Spam-Level: X-Archive-Number: 200603/213 X-Sequence-Number: 92078 On Mon, Mar 06, 2006 at 07:21:58AM -0800, Emil Rachovsky wrote: > I created a function "coalescec" which behaves the > same as coalesce, but uses an integer and a string. Is there a reason you can't use the standard COALESCE and cast the integer value to text/varchar? > Now I'm getting an error in the folowing statements : > > query := 'select "UID" from S_Users_To_Connection > where ConnID = ' || coalescec(conn_id,'null'); > execute query into nUID; > > ERROR: syntax error at or near "$2" at character 20 > QUERY: SELECT $1 into $2 What version of PostgreSQL are you running? EXECUTE INTO is new in 8.1; earlier versions would print an error like the above. > I have put UID in quotes because it seems to be a > keyword. How did you determine that? UID isn't shown in the "SQL Key Words" appendix of the documentation and I don't see it in the backend or PL/pgSQL grammars. Using it unquoted works here: test=> CREATE TABLE foo (uid integer); CREATE TABLE test=> INSERT INTO foo (uid) VALUES (1); INSERT 0 1 test=> SELECT uid FROM foo; uid ----- 1 (1 row) I'd guess that you created the column with an uppercase quoted identifier. See the documentation regarding case folding and quoted identifiers: http://www.postgresql.org/docs/8.1/interactive/sql-syntax.html#SQL-SYNTAX-IDENTIFIERS -- Michael Fuhr