I'm trying to create a table in PostgreSQL using python psycopg2. So when I execute: create_table(location) it makes the location table. I've looked at various tutorials around the web. but I just can't get it to work, any ideas?
import psycopg2
def create_table(table_name):
try:
conn = psycopg2.connect("dbname=db host=localhost user=user password=pw")
except:
print("I am unable to connect to the database")
cur = conn.cursor()
try:
cur.execute('''
CREATE TABLE public.s% (
id serial NOT NULL,
x double precision,
y double precision,
z double precision,
geom geometry,
dist double precision,
CONSTRAINT test21_pkey PRIMARY KEY (id))
''')
except:
print("Error!")
conn.commit()
conn.close()
cur.close()