X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6E4D98B9F55 for ; Fri, 18 Feb 2005 17:40:24 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 83500-08 for ; Fri, 18 Feb 2005 17:40:17 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 8120E8B9BCE for ; Fri, 18 Feb 2005 17:40:14 +0000 (GMT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id j1IHe7LO032474 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 18 Feb 2005 10:40:10 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id j1IHe7EL079401; Fri, 18 Feb 2005 10:40:07 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id j1IHe7Ge079400; Fri, 18 Feb 2005 10:40:07 -0700 (MST) (envelope-from mfuhr) Date: Fri, 18 Feb 2005 10:40:07 -0700 From: Michael Fuhr To: Michele Bendazzoli Cc: pgsql Subject: Re: plpythonu strange syntax error Message-ID: <20050218174007.GA66076@winnie.fuhr.org> References: <1108719498.4676.14.camel@mickymouse.i.mickymouse.it> <20050218095623.GA54765@winnie.fuhr.org> <1108725960.4676.18.camel@mickymouse.i.mickymouse.it> <1108727087.4676.28.camel@mickymouse.i.mickymouse.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1108727087.4676.28.camel@mickymouse.i.mickymouse.it> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.003 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200502/69 X-Sequence-Number: 5314 On Fri, Feb 18, 2005 at 12:44:47PM +0100, Michele Bendazzoli wrote: > > > Does the string that contains the Python code have carriage returns? > > > Python is picky about that; there was a thread about it recently. > > > > > > http://archives.postgresql.org/pgsql-general/2005-01/msg00792.php > > I read the thread but they seem to have miss the point: there is not a > platform issue here because postgresql, pgadmin and python are both > running on the same machine (a windows 2003 server)! PEP 278 (http://www.python.org/peps/pep-0278.txt) says this: There is no support for universal newlines in strings passed to eval() or exec. It is envisioned that such strings always have the standard \n line feed, if the strings come from a file that file can be read with universal newlines. If I'm interpreting that correctly, then regardless of platform, a string containing code to be executed must end its lines with LF (\n), not CRLF (\r\n). When running an ordinary Python script, a CRLF => LF translation presumably happens as the script is read, before the code is executed. You might not be getting that translation when using pgAdmin. As I recall from the thread, there was also concern about restoring a function that had been dumped with pg_dump. Have you checked whether the plpythonu code contains carriage returns? I forget if there's an easier way, but you could do this: SELECT replace(prosrc, '\r', 'CR') FROM pg_proc WHERE proname = 'foo'; I just created a plpythonu function with a carriage return and the above command shows this: replace ------------------ x = 1CR return x (1 row) Trying to run the function fails: SELECT foo(); ERROR: plpython: could not compile function "foo" DETAIL: exceptions.SyntaxError: invalid syntax (line 2) If I strip the carriage return from the function's prosrc column then it works: UPDATE pg_proc SET prosrc = replace(prosrc, '\r', '') WHERE proname = 'foo'; SELECT foo(); foo ----- 1 (1 row) You might try that to see if it works (be careful modifying system tables -- I'd suggest using a transaction so you can ROLLBACK if the update affected too many rows). -- Michael Fuhr http://www.fuhr.org/~mfuhr/