Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database

andydtaylor at gmail.com andydtaylor at gmail.com
Wed Jan 9 19:19:10 EST 2013


Hi John,

He're the code I would like to see work. The cursor_to is an oversight. I extracted this element from some other code in an attempt to isolate/resolve the problem myself, hence having a simplified table version. Which works actually, but unfortunately that's not educating me suffieciently. Actual error message I see follows.

- - - - - - - - - - - - - - - - - - - - - - - - - 
Code:

#!/usr/bin/python
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.execute("CREATE TABLE tubecross (id serial PRIMARY KEY, station_code char, SAJ interval, SPB interval, SOQ interval);")
   cursor.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) VALUES (%s, %s, %s, %s)",(SAJ, 00:00, 00:22, 00:27))
   db.commit()

if __name__ == "__main__":
	main()

- - - - - - - - - - - - - - - - - - - - - - - - - 
Error Message:

andyt at andyt-ThinkPad-X61:~/projects/django-stringer/Other/TFLJPAPI$ python creat_db_exp.py
  File "creat_db_exp.py", line 15
    cursor.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) VALUES (%s, %s, %s, %s)",(SAJ, 00:00, 00:22, 00:27))
                                                                                                         ^
SyntaxError: invalid syntax


Thanks for your help



More information about the Python-list mailing list