471,305 Members | 1,311 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,305 software developers and data experts.

insert string problems..

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'

if i do int(yer) , 019 change to 19 ..
How can i do int yer string with 0 ?

Oct 28 '07 #1
4 1467
Also..
a="123,245,1235,663"
cursor.execute("SELECT id, name FROM data WHERE id in (%s)", (a,))
In this query must be:
SELECT id, name FROM data WHERE id in (123,245,1235,663)
but it looks:
SELECT id, name FROM data WHERE id in ("123,245,1235,663")
How can i delete " ?

Oct 28 '07 #2
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'

if i do int(yer) , 019 change to 19 .. How can i do int yer string with
0 ?
Integers with a leading 0 are interpreted as base 8 (octal). You can't
write 019, because there is no digit "9" in octal.

Why do you need a leading zero?
--
Steven.
Oct 28 '07 #3
On Oct 28, 9:45 am, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com.auwrote:
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'
if i do int(yer) , 019 change to 19 .. How can i do int yer string with
0 ?

Integers with a leading 0 are interpreted as base 8 (octal). You can't
write 019, because there is no digit "9" in octal.

Why do you need a leading zero?

--
Steven.
Thank you steven.
I must use 019 beacause my system algoritm in this way..
And what about second question ?

Oct 28 '07 #4
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
believe!

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.

Ciao,
Marc 'BlackJack' Rintsch
Oct 28 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by me | last post: by
2 posts views Thread by John Tyce | last post: by
4 posts views Thread by bardo | last post: by
reply views Thread by Tim::.. | last post: by
2 posts views Thread by Polyhedron_12 | last post: by
4 posts views Thread by David A. Osborn | last post: by
6 posts views Thread by Eric Lilja | last post: by
5 posts views Thread by Rob | last post: by
5 posts views Thread by =?Utf-8?B?bXBhaW5l?= | last post: by
2 posts views Thread by Terry Reedy | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.