473,396 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

calling Postgresql stored procedure

I am using Python 2.4 and Postgresql 8.2 database server.

On the database I have created a stored function, example,
CREATE OR REPLACE FUNCTION calculateaverage()

I created a new python script and would like to call my database
stored function.

How can I call a database stored function/procedure in python?

Thanks

May 30 '07 #1
4 5644
Alchemist schrieb:
I am using Python 2.4 and Postgresql 8.2 database server.

On the database I have created a stored function, example,
CREATE OR REPLACE FUNCTION calculateaverage()

I created a new python script and would like to call my database
stored function.

How can I call a database stored function/procedure in python?
with :

SELECT calculateaverage() FROM ... WHERE ... ;

happy pythoning

Herbert
May 30 '07 #2
In article <11*********************@q69g2000hsb.googlegroups. com>,
Alchemist <al********@gmail.comwrote:
I am using Python 2.4 and Postgresql 8.2 database server.

On the database I have created a stored function, example,
CREATE OR REPLACE FUNCTION calculateaverage()

I created a new python script and would like to call my database
stored function.

How can I call a database stored function/procedure in python?
You need a layer in between Python and Postgres so that they can talk to
one another. If you don't have one, try this one (use version 2, not
version 1.x):
http://www.initd.org/tracker/psycopg

Good luck

--
Philip
http://NikitaTheSpider.com/
Whole-site HTML validation, link checking and more
May 31 '07 #3
Thanks for your help.

My stored procedure is written in pythonpl. I noticed that SELECT
queries are executed correctly (results are returned to my script)
whereas UPDATE queries are not being performed as the data is not
updated.

I am using a database user with read/write access to the database.

Is there a commit statement in plpython? (e.g. plpy.commit())
Why are UPDATEs failing?

Jun 1 '07 #4
In article <11**********************@h2g2000hsg.googlegroups. com>,
Alchemist <al********@gmail.comwrote:
Thanks for your help.

My stored procedure is written in pythonpl. I noticed that SELECT
queries are executed correctly (results are returned to my script)
whereas UPDATE queries are not being performed as the data is not
updated.
Aha! So the problem is not really with how to call Postgres stored
procs, but that you're not getting the results you expect from some
calls.
I am using a database user with read/write access to the database.

Is there a commit statement in plpython? (e.g. plpy.commit())
Did you try that? Did you check the documentation?
Why are UPDATEs failing?
I'm not familiar with plpy but if it is compliant with the Python DBAPI
(PEP 249) specification then, yes, it has a .commit() method and yes,
you must call it after DDL statements.

From the PEP: "Note that if the database supports an auto-commit
feature, this must be initially off."
http://www.python.org/dev/peps/pep-0249/

In short, either turn on autocommit or start calling .commit().

--
Philip
http://NikitaTheSpider.com/
Whole-site HTML validation, link checking and more
Jun 1 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ralph | last post by:
My company is researching the idea of moving from a very large, old and complex UniData DB to something else that is newer and quicker. I was thinking about PostgreSQL, but am not sure PostgreSQL...
18
by: Jarrod Morrison | last post by:
Hi All I was wondering if there is a way to call a stored procedure from inside another stored procedure. So for example my first procedure will call a second stored procedure which when...
3
by: Bob.Henkel | last post by:
I write this to tell you why we won't use postgresql even though we wish we could at a large company. Don't get me wrong I love postgresql in many ways and for many reasons , but fact is fact. If...
5
by: Zlatko Matić | last post by:
Hello. How can I call some functions on MSDE when working in .mdb ? Especially in-line functions which are similar to stored procedures. How can I use MSDE in-line functions as recordsource for...
1
by: Mark | last post by:
I would love to see a snippet of .NET code that either: 1. Executes a raw SQL statement against MySQL or PostgreSql. 2. Executes a stored procedure on PostgreSql. Ideally both examples would...
2
by: Woody Splawn | last post by:
I am using SQL Server 2000 as the back-end. I have created a stored procedure in SQL server called usp_AddContract. This Stored procedure inserts a new contract into a contracts table. I have...
0
by: btober | last post by:
Say I have a type defined as city (varchar, varchar(2), numeric, numeric) What would be the syntax for calling a stored procedure defined with this type as a parameter, i.e., something like ...
2
by: singlal | last post by:
Hi, my question was not getting any attention because it moved to 2nd page; so posting it again. Sorry for any inconvenience but I need to get it resolved fast. Need your help! ...
4
by: eighthman11 | last post by:
I'm calling a stored procedure on a sql server from an access application. I just need the stored procedure to run I do not need any data returned from the stored procedure to my Access...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.