Re: Calling Python functions with parameters

From: aklaver(at)comcast(dot)net (Adrian Klaver)
To: "user" <2567jl03(at)sneakemail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Calling Python functions with parameters
Date: 2008-07-18 21:04:04
Message-ID: 071820082104.9023.48810544000A9CAD0000233F22007610649D0A900E04050E@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

-------------- Original message ----------------------
From: "user" <2567jl03(at)sneakemail(dot)com>
> I am having a problem with the simplest of Python functions, so I must be
> doing something wrong. After hours of searching and trying many options, I
> need the key that my puny brain is missing here.
>
> I cannot pass parameters to a plpythonu function. I have tried within psql
> and with pgAdmin III (which adds IN or INOUT to the parameter list - which I
> can't find documented). I'm an advanced Python programmer but a beginning
> PostgreSQL user.
>
> Here is what I have, which I copied almost verbatim from example code:
> ----------------------------
> test_dev-# \p
> create or replace function testf5i(a integer,b integer)
> RETURNS integer AS $$
> if a > b:
> return a
> return b
> $$ language plpythonu
>
>
> test_dev-# \g
> CREATE FUNCTION
> test_dev=# select testf5i(1,2);
> ERROR: plpython: function "testf5i" failed
> DETAIL: exceptions.NameError: global name 'a' is not defined

Take a look at:
http://www.postgresql.org/docs/8.1/interactive/plpython.html#PLPYTHON-FUNCS

The form you are trying to use is supported in 8.2+.

--
Adrian Klaver
aklaver(at)comcast(dot)net

Browse pgsql-general by date

  From Date Subject
Next Message Francisco Reyes 2008-07-18 21:46:18 Re: Reducing memory usage of insert into select operations?
Previous Message Tom Lane 2008-07-18 21:00:56 Re: Reducing memory usage of insert into select operations?