pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steve White <swhite@aip.de>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Kevin Grittner <Kevin.Grittner@wicourts.gov>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: Feature request: include script file into function body
Date: Wed, 2 Feb 2011 12:18:08 +0100
Message-ID: <20110202111808.GA21282@cashmere.aip.de> (raw)
In-Reply-To: <AANLkTi=7C8xFYF7uQW0y+si8oNdKoY2NX8jc4bU0GWvY@mail.gmail.com>
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>
	<AANLkTi=7C8xFYF7uQW0y+si8oNdKoY2NX8jc4bU0GWvY@mail.gmail.com>

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
| -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -



view thread (33+ messages)  latest in thread

Message-ID: <20110202111808.GA21282@cashmere.aip.de>
Permalink:  ../20110202111808.GA21282@cashmere.aip.de/
Also on:    postgresql.org/message-id/20110202111808.GA21282@cashmere.aip.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: swhite@aip.de, robertmhaas@gmail.com, Kevin.Grittner@wicourts.gov, tgl@sss.pgh.pa.us
  Subject: Re: Feature request: include script file into function body
  In-Reply-To: <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> <AANLkTi=7C8xFYF7uQW0y+si8oNdKoY2NX8jc4bU0GWvY@mail.gmail.com> <20110202111808.GA21282@cashmere.aip.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox