Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id DCA9E1337990 for ; Wed, 2 Feb 2011 07:18:17 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 08470-06 for ; Wed, 2 Feb 2011 11:18:10 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail0.aip.de (maigret.aip.de [141.33.160.2]) by mail.postgresql.org (Postfix) with SMTP id 13D4A133616B for ; Wed, 2 Feb 2011 07:18:09 -0400 (AST) Received: (qmail 27746 invoked from network); 2 Feb 2011 10:12:41 -0000 Received: from cashmere.aip.de (141.33.4.98) by mailout.aip.de with SMTP; 2 Feb 2011 10:12:41 -0000 Received: from cashmere.aip.de (localhost.localdomain [127.0.0.1]) by cashmere.aip.de (8.13.8/8.13.8) with ESMTP id p12BI8mV022280; Wed, 2 Feb 2011 12:18:08 +0100 Received: (from swhite@localhost) by cashmere.aip.de (8.13.8/8.13.8/Submit) id p12BI8vT022279; Wed, 2 Feb 2011 12:18:08 +0100 X-Authentication-Warning: cashmere.aip.de: swhite set sender to swhite@aip.de using -f Date: Wed, 2 Feb 2011 12:18:08 +0100 From: Steve White To: Robert Haas Cc: Kevin Grittner , Tom Lane , pgsql-bugs@postgresql.org Subject: Re: Feature request: include script file into function body Message-ID: <20110202111808.GA21282@cashmere.aip.de> References: <20110201112120.GA1327@cashmere.aip.de> <26900.1296576145@sss.pgh.pa.us> <20110201164422.GA3023@cashmere.aip.de> <4D47EB12020000250003A0EE@gw.wicourts.gov> <20110201185004.GA7511@cashmere.aip.de> <4D480622020000250003A10C@gw.wicourts.gov> <1191.1296588973@sss.pgh.pa.us> <20110201195915.GA8252@cashmere.aip.de> <4D481423020000250003A123@gw.wicourts.gov> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.2i "Organization: Astrophysikalisches Institut Potsdam" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/31 X-Sequence-Number: 29303 Hi, Robert, On 1.02.11, Robert Haas wrote: > > Can't you already do it this way: > > \set yadda `cat yadda_yadda.py` > CREATE FUNCTION yadda_yadda() returns text language plpythonu AS > :'yadda'; > > I guess it probably won't work on Windows... > This would also satisfy my immediate needs... if only I could get it to work. I made a file 'yadda_yadda.py' containing only the line: print 'hello world' ==================================================================== d=# \set yadda `cat yadda_yadda.py` d=# \echo :yadda print 'hello world' ==================================================================== So far, so good. But the :'yadda'; produces an error--it seems the variable yadda isn't expanded in the presence of the quotes. ==================================================================== d=# CREATE FUNCTION yadda_yadda() returns text language plpythonu AS :'yadda'; ERROR: syntax error at or near ":" LINE 2: :'yadda'; ==================================================================== Without the quotes, the colon expands the variable, but not into a string function body: ==================================================================== d=# CREATE FUNCTION yadda_yadda() returns text language plpythonu AS :yadda; ERROR: syntax error at or near "print" LINE 2: print 'hello world'; ==================================================================== Just for completeness and blind optimism let's try putting string delimiters on the outside. The command succeeds but with the wrong effect. ==================================================================== d=# CREATE OR REPLACE FUNCTION yadda_yadda() returns text language plpythonu AS $$:yadda$$; CREATE FUNCTION cepheids=# \df+ yadda_yadda List of functions Schema | Name | Result data type | Argument data types | Type | Volatility | Owner | Language | Source code | Description -----------+-------------+------------------+---------------------+--------+------------+----------+-----------+-------------+------------- astronomy | yadda_yadda | text | | normal | volatile | cepheids | plpythonu | :yadda | ==================================================================== Please explain. -- | - - - - - - - - - - - - - - - - - - - - - - - - - | Steve White +49(331)7499-202 | E-Science Zi. 27 Villa Turbulenz | - - - - - - - - - - - - - - - - - - - - - - - - - | Astrophysikalisches Institut Potsdam (AIP) | An der Sternwarte 16, D-14482 Potsdam | | Vorstand: Prof. Dr. Matthias Steinmetz, Peter A. Stolz | | Stiftung privaten Rechts, Stiftungsverzeichnis Brandenburg: III/7-71-026 | - - - - - - - - - - - - - - - - - - - - - - - - -