Python: psycopg2.ProgrammingError: syntax error at end of input

This error may come in different flavours, but the majority of the time its because the SQL being executed has a quote around the %s value.

Strangely enough, this seems rather counter intuitive to everything we've been using thus far. I'm not sure where abouts down the chain this happens, but the quotes are added for us automagically.

Error thrown:

psycopg2.ProgrammingError: syntax error at end of input
LINE 1: ...nd-post/1010314'', 'E'Senior Business Development Manager'')

Cause:

cursor.execute("INSERT INTO table_name (id, link, title) VALUES (%s, '%s', '%s')", (id, link, title))

Fixed by removing quotes:

cursor.execute("INSERT INTO table_name (id, link, title) VALUES (%s, %s, %s)", (id, link, title))

[ Source ]

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog