Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database

andydtaylor at andydtaylor at
Thu Jan 10 00:52:12 CET 2013


I'm a bit stuck on this "INSERT INTO" syntax error. I have no idea why it's not working actually... I've tried changing column types to char but that didn't work. I've gone a bit blind looking at it, but hopefully you can set me right. With the '#'d out lines instead the file does work.

What am I missing?



import psycopg2
import sys

def main():
   db = psycopg2.connect(
      host = 'localhost',
      database = 'gisdb',
      user = 'postgres',
      password = '######'
   cursor = db.cursor()
   cursor.execute("DROP TABLE IF EXISTS tubecross")
   cursor_to.execute("CREATE TABLE tubecross (id serial PRIMARY KEY, station_code char, SAJ interval, SPB interval, SOQ interval);")
   #cursor.execute("CREATE TABLE tubecross (id serial PRIMARY KEY, num integer, data varchar);") 
   #cursor.execute("INSERT INTO tubecross (num, data) VALUES (%s, %s)",(900, "9abc'def"))
   cursor_to.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) VALUES (%s, %s, %s, %s)",(SAJ, 00:00, 00:22, 00:27))

if __name__ == "__main__":

More information about the Python-list mailing list