Calling a Postgres Function using CGI written in Python

F

Fuzzydave

I need to call a function stored in Postgres which does a lot of the db
and calculation work
all the SQL queries are hardcoded in a file called cmi.py. What i need
to do is too to call
my function from postgres passing in my product_code variable into it
and returning the
value from the query into a variable i can print to screen as part of a
HTML page.

I am sure its very easy but have never done anything in python as have
none of the guys
i work with making this a bit of a problem.

Cheers Guys
David
 
F

Fuzzydave

I did do a google search i have looking through the one python book i
have
and there are plenty of references for how to write a function in
Python but
not as many on how to call a function stored in postgres using python I
have
tried the conn.execute(cmi_grn_cost(productCode)) and also the
conn.callproc(cmi_grn_cost(productCode)) commands where conn is the
connection object and cmi_grn_cost() is the the function getting called
from
Postgres and productCode is the variable to passed.
 
D

Dennis Lee Bieber

not as many on how to call a function stored in postgres using python I

I'd expect you'd call a stored procedure the same way you would
using any other tool... Submit a suitable formatted query /string/
have
tried the conn.execute(cmi_grn_cost(productCode)) and also the
conn.callproc(cmi_grn_cost(productCode)) commands where conn is the

That syntax is trying to pass the return of a Python function named
cmi_grn_cost to PostgreSQL.

Try something more like (presuming it returns a result set, you
probably need to create a cursor and invoke execute on the cursor)

csr.execute("select cmi_grn_cost(%s)", productCode)

where the %s is replaced with whatever your db-adapter uses for
parameter markers (MySQLdb uses %s, and kinterbasdb uses ? as I
recall... but the PostgreSQL adapters might use something else).
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top