Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

python and Postgresq

1 view
Skip to first unread message

Andy dixon

unread,
Nov 23, 2009, 5:03:07 AM11/23/09
to
Hi,

Does anyone have a link to, or can provide an example script for using
python-pgsql (http://pypi.python.org/pypi/python-pgsql/) or if someone can
recommend an alternative, that would be fantastic.

Thanks!

Andy Dixon

Diez B. Roggisch

unread,
Nov 23, 2009, 5:22:15 AM11/23/09
to
Andy dixon wrote:

I'd recommend psycopg2.

This is an introduction:

http://www.devx.com/opensource/Article/29071

But google yields tons more. And make sure you read the python db api 2.0
spec, this should give you the general idea on how to work with Python &
RDBMS, which is nicely abstracted away from the actual database.

http://www.python.org/dev/peps/pep-0249/

Diez

Ben Finney

unread,
Nov 23, 2009, 6:01:54 AM11/23/09
to
"Andy dixon" <a...@malcol.org> writes:

"Diez B. Roggisch" <de...@nospam.web.de> writes:

> I'd recommend psycopg2.

I'd recommend installing ‘psycopg2’, but using it at a slight distance
by installing ‘SQLAlchemy’ <URL:http://sqlalchemy.org/> to give a useful
Pythonic access layer while having full access to SQL whenever needed.

--
\ “People come up to me and say, ‘Emo, do people really come up |
`\ to you?’” —Emo Philips |
_o__) |
Ben Finney

Andy dixon

unread,
Nov 23, 2009, 5:36:26 AM11/23/09
to
"Diez B. Roggisch" <de...@nospam.web.de> wrote in message
news:7mv62nF...@mid.uni-berlin.de...

Amazing. Works like a charm!

Thanks..

I used the code (stripping out certain bits) if anyone else may find it
useful:

#!/usr/bin/env python
import psycopg

def main():
connection = psycopg.connect('host=<HOST> dbname=<DB> user=<USER>
password=<PASSWORD>')
mark = connection.cursor()
query='SELECT * FROM table'
mark.execute(query)
record = mark.fetchall()
for i in record:
print i
return

if __name__ == '__main__':
main()

Krishnakant

unread,
Nov 23, 2009, 6:20:04 AM11/23/09
to Diez B. Roggisch, pytho...@python.org

Python-pgsql is a much better choice when it comes to big applications,
specially if you are going to deal with xml-rpc. I have found that
python-pgsql handles integers and other such postgresql datatypes
better.

Happy hacking.
Krishnakant.


Diez B. Roggisch

unread,
Nov 23, 2009, 6:37:36 AM11/23/09
to
Krishnakant wrote:

Where is the connection between XMLRPC and psql? And can you elaborate on
what and how pgsql handles things better than psycopg2?

Diez

Tim Roberts

unread,
Nov 25, 2009, 2:19:01 AM11/25/09
to
Krishnakant <hack...@gmail.com> wrote:
>
>Python-pgsql is a much better choice when it comes to big applications,
>specially if you are going to deal with xml-rpc. I have found that
>python-pgsql handles integers and other such postgresql datatypes
>better.

I wonder if you would mind expanding on the experiences that lead you to
say this. I've use both extensively (plus the old "pg"), and I've found
psycopg to be unconditionally the better choice, especially for big
applications where performance is critical.
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

0 new messages