psycopg2 cursor.execute CREATE TABLE issue
andydtaylor at gmail.com
andydtaylor at gmail.com
Sun Jan 6 16:38:29 EST 2013
Hi all,
I'm trying to create a process which will create a new table and populate it.
But something is preventing this from working, and I don't know enough to figure it out, despite having spent most of today reading up. The code executes with no error, yet no table is created or populated.
Can anyone offer me some advice? code below.
Thanks,
Andy
#!/usr/bin/python
import psycopg2
import sys
def main():
db = psycopg2.connect(
host = 'localhost',
database = 'gisdb',
user = 'postgres',
password = 'L1ncoln0ut@'
)
cursor = db.cursor()
cursor.execute("CREATE TABLE test (id serial PRIMARY KEY, num integer, data varchar);")
cursor.execute("INSERT INTO test (num, data) VALUES (%s, %s)",(100, "abc'def"))
if __name__ == "__main__":
main()
More information about the Python-list
mailing list