Differences between revisions 4 and 5
Revision 4 as of 2007-10-07 02:50:35
Size: 2625
Editor: pool-68-238-14-194
Comment:
Revision 5 as of 2007-10-07 02:54:54
Size: 2653
Editor: pool-68-238-14-194
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
#FORMAT restructuredtext

================== ====================================================================================
              task                                                                           postgresql
================== ====================================================================================
   create database                                                                        createdb mydb
------------------ ------------------------------------------------------------------------------------
 command-line tool                                                                         psql -d mydb
------------------ ------------------------------------------------------------------------------------
          GUI tool                                                                             pgadmin3
------------------ ------------------------------------------------------------------------------------
    install module                                                                easy_install psycopg2
------------------ ------------------------------------------------------------------------------------
            import                                                               from psycopg2 import *
------------------ ------------------------------------------------------------------------------------
           connect conn = connect("dbname='testdb' user='me' host='localhost' password='mypassword'”)
------------------ ------------------------------------------------------------------------------------
        get cursor                                                                 curs = conn.cursor()
------------------ ------------------------------------------------------------------------------------
    execute SELECT                                                    curs.execute('SELECT * FROM tbl')
------------------ ------------------------------------------------------------------------------------
             fetch                                   curs.fetchone(); curs.fetchall(); curs.fetchmany()
------------------ ------------------------------------------------------------------------------------
use bind variables                curs.execute('SELECT * FROM tbl WHERE col = %(varnm)s', {'varnm':22})
------------------ ------------------------------------------------------------------------------------
            commit                                                            conn.commit()  (required)
------------------ ------------------------------------------------------------------------------------

DbApiCheatSheet (last edited 2010-03-09 03:54:30 by bb14f857)

Unable to edit the page? See the FrontPage for instructions.