Re: [PATCHES] 2 line patch to allow plpythonu functions to return void ...

2006-02-25 Thread Tom Lane
James Robinson [EMAIL PROTECTED] writes:
 Shamelessly cloned from the parallel code in pltcl, an exception for  
 void in denying pseudotypes being returned. Pl/tcl didn't reference  
 VOIDOID anywhere else, so ... .

This sort of thing normally requires more thought than just removing
the safety check.  What happens when the python code does/doesn't return
a value, in both cases (declared return type void or not)?

regards, tom lane

---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [PATCHES] 2 line patch to allow plpythonu functions to return void ...

2006-02-25 Thread Harald Armin Massa
Tom,This sort of thing normally requires more thought than just removingthe safety check.What happens when the python code does/doesn't return
a value, in both cases (declared return type void or not)?python functions are specified to return None, if no return is given. I recommend to also see a plpython function as a Python function, and return None if no return is specified.
-- GHUM Harald Massapersuadere et programmareHarald Armin MassaReinsburgstraße 202b70197 Stuttgart0173/9409607-When I visit a mosque, I show my respect by taking off my shoes. I follow the customs, just as I do in a church, synagogue or other holy place. But if a believer demands that I, as a nonbeliever, observe his taboos in the public domain, he is not asking for my respect, but for my submission. And that is incompatible with a secular democracy.


Re: [PATCHES] 2 line patch to allow plpythonu functions to return void ...

2006-02-25 Thread James Robinson


On Feb 25, 2006, at 12:10 PM, Tom Lane wrote:


James Robinson [EMAIL PROTECTED] writes:

Shamelessly cloned from the parallel code in pltcl, an exception for
void in denying pseudotypes being returned. Pl/tcl didn't reference
VOIDOID anywhere else, so ... .


This sort of thing normally requires more thought than just removing
the safety check.  What happens when the python code does/doesn't  
return

a value, in both cases (declared return type void or not)?

regards, tom lane


Yes of course.

Here's some permutations of declared void functions explictly  
returning a value or not, with the closest thing to void in Python  
being None [ which is currently mapped to SQL NULL ] ...


create or replace function void_ret_notvoid() returns void as
$$
return 12
$$  language plpythonu;

-- return value '' comes decorated with oid 2278, which seems to be  
VOIDOID. The 12 integer gets discarded. Ugly, yes.


create or replace function void_ret_none() returns void as
$$
return None
$$  language plpythonu;

-- Once again, returned oid to client is 2278, and likewise for the  
subsequent one


select void_ret_none() is null;

create or replace function void_ret_falloff_none() returns void as
$$
x = 12 + 4
$$  language plpythonu;


-- This one returns oid 23, with value NULL.

create or replace function notvoid_ret_none() returns int as
$$
return None
$$  language plpythonu;


Now, the python language semantics are that if a function does not  
explictly return a value, None is implictly returned:


jlrobins:~ jlrobins$ python
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type help, copyright, credits or license for more information.
 def falloff():
... x = 12
...
 val = falloff()
 val is None
True

So there's a bit of a mismatch between Python and SQL semantics since  
Python's None is already being used to represent NULL [ of whatever  
datatype the pl function was described to return at the SQL level ]  
in plpython.


The ugliest case above is certainly the first one -- function  
declared to be void explicitly returning a not-None value. That  
should probably cause an SQL-level error. Can't really test it a  
function compile time, since Python variables are not typed, only  
what they reference are.


The intent was to have to keep from having to declare a bogus return  
type for a a procedure that returns no meaningful results at all --  
such as one which does nothing but inserts or updates or what have you.


I suspect that all of the above functions returned VOIDOID decorating  
the return result due to machinery higher-up than plpython -- the  
postgres typing system itself, so those cases are probably silly  
examples, other than showing that it doesn't immediately crash. Which  
you probably would rather be shown a much higher confidence proof  
that the system is still correct aside from not immediately going  
down in flames.


I'll go back to lurking and reading -- is the plpgsql source the best  
model for reading up on procedure language implementation? Thanks.



James Robinson
Socialserve.com


---(end of broadcast)---
TIP 2: Don't 'kill -9' the postmaster


[PATCHES] 2 line patch to allow plpythonu functions to return void ...

2006-02-24 Thread James Robinson
Shamelessly cloned from the parallel code in pltcl, an exception for  
void in denying pseudotypes being returned. Pl/tcl didn't reference  
VOIDOID anywhere else, so ... .


Allowed following trivial test function to succeed:

create or replace function set_gd(int) returns void as
$$
GD['global_count'] =  args[0]
$$  language plpythonu volatile;






allow_plpython_return_void.diff
Description: Binary data



James Robinson
Socialserve.com


---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly