postgres example

Mark McEahern marklists at mceahern.com
Sat Jan 12 15:20:28 EST 2002


# create the db
$ createdb testdb

# create a table
$ psql -c "create table foo (name varchar(100));" testdb

# insert a record
$ psql -c "insert into foo values ('test');" testdb

# start python
$ python

# import PgSQL
>>> from pyPgSQL import PgSQL

# get a connection
>>> conn = PgSQL.Connection("dbname=testdb")

# get a cursor
>>> cursor = conn.cursor()

# get record from foo
>>> sql = "select * from foo;"
>>> cursor.execute(sql)
>>> cursor.fetchone()
['test']

Cheers,

// mark




More information about the Python-list mailing list