Re: Feature request: include script file into function body

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Steve White <swhite(at)aip(dot)de>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: Feature request: include script file into function body
Date: 2011-02-02 11:41:24
Message-ID: AANLkTik1Rn+GfSgC_KU7mxYAtJavvQM9SjdReWFqdkP_@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello

probably you need a third form of expansion - not implemented yet

":$$var$$

escaping :'xxx' is designed for SQL language, not for Python :(

Regards

Pavel

2011/2/2 Steve White <swhite(at)aip(dot)de>:
> 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
> | -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2011-02-02 15:28:56 Re: Feature request: include script file into function body
Previous Message Steve White 2011-02-02 11:18:08 Re: Feature request: include script file into function body