python and Postgresq

Discussion in 'Python' started by Andy dixon, Nov 23, 2009.

  1. Andy dixon

    Andy dixon Guest

    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
     
    Andy dixon, Nov 23, 2009
    #1
    1. Advertising

  2. Andy dixon wrote:

    > 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.


    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
     
    Diez B. Roggisch, Nov 23, 2009
    #2
    1. Advertising

  3. Andy dixon

    Andy dixon Guest

    "Diez B. Roggisch" <> wrote in message
    news:-berlin.de...
    > Andy dixon wrote:
    >
    >> 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.

    >
    > 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


    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()
     
    Andy dixon, Nov 23, 2009
    #3
  4. Andy dixon

    Krishnakant Guest

    On Mon, 2009-11-23 at 11:22 +0100, Diez B. Roggisch wrote:
    > Andy dixon wrote:
    >
    > > 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.

    >
    > 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.


    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.
     
    Krishnakant, Nov 23, 2009
    #4
  5. Krishnakant wrote:

    > On Mon, 2009-11-23 at 11:22 +0100, Diez B. Roggisch wrote:
    >> Andy dixon wrote:
    >>
    >> > 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.

    >>
    >> 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.

    >
    > 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.


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

    Diez
     
    Diez B. Roggisch, Nov 23, 2009
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    771
  2. Paul Moore
    Replies:
    0
    Views:
    655
    Paul Moore
    Mar 1, 2008
  3. Martin v. Löwis
    Replies:
    0
    Views:
    691
    Martin v. Löwis
    Mar 1, 2008
  4. cnb
    Replies:
    0
    Views:
    301
  5. Replies:
    0
    Views:
    90
Loading...

Share This Page