This is a discussion on How to 'register' functions, so they can be called (plpythonu) within the Pgsql General forums, part of the PostgreSQL category; --> I am defining some functions using plpythonu, through the standard means. Here I have one function (test1) which calls ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I am defining some functions using plpythonu, through the standard means. Here I have one function (test1) which calls another (testfunc). When I excute this I get the following error: ERROR: plpython: function "test1" failed DETAIL: <type 'exceptions.NameError'>: global name 'testfunc' is not defined However, from the console, select testfunc('test') works fine. I was wondering how do I 'register'/'reference' these functions so that one function can call another? I am guessing this is important, i.e. how will I access the complete functionality of the general python libs? Cheers, Blay. PS functions are defined in the usual way - e.g. create or replace function test1(text) returns integer as $$ return 1 $$ language plpythonu; ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match |
| |||
| blay bloo wrote: > I am defining some functions using plpythonu, through the standard means. > > Here I have one function (test1) which calls another (testfunc). When > I excute this I get the following error: > > ERROR: plpython: function "test1" failed > DETAIL: <type 'exceptions.NameError'>: global name 'testfunc' is not defined > > However, from the console, select testfunc('test') works fine. > > I was wondering how do I 'register'/'reference' these functions so > that one function can call another? You can't, because the name you give to the function lives in Postgres' namespace, not Python's. Therefore you can only call the other function using the SPI interface that PL/Python offers you. > I am guessing this is important, > i.e. how will I access the complete functionality of the general > python libs? This is quite different -- I'm guessing the Python library can be accessed via normal means. What you cannot do is use Postgres' CREATE FUNCTION to define a regular Python function (i.e. you cannot extend the "library"). -- Alvaro Herrera http://www.advogato.org/person/alvherre Bob [Floyd] used to say that he was planning to get a Ph.D. by the "green stamp method," namely by saving envelopes addressed to him as 'Dr. Floyd'. After collecting 500 such letters, he mused, a university somewhere in Arizona would probably grant him a degree. (Don Knuth) ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings |
| ||||
| blay bloo wrote: > I am defining some functions using plpythonu, through the standard means. > > Here I have one function (test1) which calls another (testfunc). When > I excute this I get the following error: > > ERROR: plpython: function "test1" failed > DETAIL: <type 'exceptions.NameError'>: global name 'testfunc' is not defined You need to call it as an SQL statement "SELECT testfunc(...)" > However, from the console, select testfunc('test') works fine. I believe the python embedder mangles the function names when it loads them into PG, so you can't call them directly. -- Richard Huxton Archonet Ltd ---------------------------(end of broadcast)--------------------------- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly |
| Thread Tools | |
| Display Modes | |
|
|