2653
Comment:
|
2640
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
#FORMAT restructuredtext | #FORMAT rst |
Line 27: | Line 27: |
------------------ ------------------------------------------------------------------------------------ | ================== ==================================================================================== |
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) |