dbTalk Databases Forums  

plPython Resultset

comp.databases.postgresql comp.databases.postgresql


Discuss plPython Resultset in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Philipp Kraus
 
Posts: n/a

Default plPython Resultset - 09-05-2007 , 04:00 PM






Hello,

I've written my first Stored Procedure with plPython (I had coded pgSQL
only). This is the function:

lnSemesterID = args[0]
lnNode = args[1]
lnDeep = args[2]

loSQL = plpy.prepare("SELECT uebergeord FROM r_hierarchie WHERE
semester=$1 AND untergeord=$2", ["numeric", "numeric"])

plpy.execute(loSQL, [lnSemesterID, lnNode], 1)
loRow = plpy.fetchone()

return lnDeep

It's not finished, but how I can get the result? The fetchall /
fetchone raise an error. I can get one or no row from the table.

Another question for this function is, can I call a function
recursively like this:

self.myfunction(param1, param2, param3)

or must I call it with a statement:

plpy.execute("Select myfuntion(param1, param2, param3") ?

Thanks for help

Phil


Reply With Quote
  #2  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: plPython Resultset - 09-06-2007 , 06:04 AM






Philipp Kraus <philipp.kraus (AT) flashpixx (DOT) de> wrote:
Quote:
I've written my first Stored Procedure with plPython (I had coded pgSQL
only). This is the function:
[...]

Quote:
plpy.execute(loSQL, [lnSemesterID, lnNode], 1)
loRow = plpy.fetchone()
[...]

Quote:
It's not finished, but how I can get the result? The fetchall /
fetchone raise an error. I can get one or no row from the table.
I don't know anything about Python, but there is no fetchone() or
fetchall() function in pl/Python (judging from the source code).

The documentation says that

The result object emulates a list or dictionary object.
The result object can be accessed by row number and column name.

So plpy.execute *returns* a Python data structure that contains the results.

Regarding your second question, I don't know, but I think that you'll
have to use SQL to call one pl/Python function from another.

Yours,
Laurenz Albe


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.