insert string problems..

Marc 'BlackJack' Rintsch bj_666 at
Sun Oct 28 09:27:48 CET 2007

On Sun, 28 Oct 2007 00:24:34 -0700, Abandoned wrote:

> Hi..
> I want to insert some data to postgresql..
> My insert code:
> yer="019"
> cursor.execute("INSERT INTO ids_%s (id) VALUES (%s)", (yer, id))
> I don't want to use % when the insert operation.
> in this code give me this error:
> psycopg2.ProgrammingError: syntax error at or near "'019'"
> LINE 1: SELECT link_id from linkkeywords_'019'

You are executing an INSERT and get an error about a SELECT!?  Hard to

But in both SQL statements you try to insert table names via placeholders.
This doesn't work as those placeholders are *values* that will be escaped.
The errormessage is quite clear IMHO::

  SELECT link_id from linkkeywords_'019'

That's not a valid table name because of the ' that got added when
inserting the *value* '019'.

Starting to number tables and the need to dynamically create table names is
usually sign of a bad schema design BTW.

	Marc 'BlackJack' Rintsch

More information about the Python-list mailing list