import psycopgdef getdsn(db = None, user = None, passwd = None, host = None): if user == None: import os, pwd user = pwd.getpwuid(os.getuid())[0] if db == None: db = user dsn = 'dbname=%s user=%s' % (db, user) if passwd != None: dsn += ' password=' + passwd if host != None: dsn += ' host=' + host return dsndsn = getdsn()print "Connecting to %s" % dsndbh = psycopg.connect(dsn)print "Connection successful."cur = dbh.cursor()cur.execute("""CREATE TABLE myTable(mynum integer UNIQUE,mystring varchar(30))""")cur.execute("INSERT INTO myTable VALUES (5, 'Five')")cur.execute("INSERT INTO myTable VALUES (0)")dbh.commit()dbh.close()
Name (required)
email (will not be published) (required)
Website