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

0 comments

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 ]

0 comments:

Post a Comment

Leave your thoughts ...
---
If you are having trouble with copy/pasting in comments, you need to sign in or click 'Preview'. For more information about this Firefox bug, see here.

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