473,287 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 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 1565
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: me | last post by:
I'm also having problems getting the bulk insert to work. I don't know anything about it except what I've gleened from BOL but I'm not seeming to get anywhere...Hopefully there is some little (or...
2
by: John Tyce | last post by:
When a button is clicked, a date is inserted or added into a combo box like this : ComboBox.Items.Add(string) or ComboBox.Items.Insert(0,string); Either way, the new string does not show up in the...
4
by: bardo | last post by:
Hello all, I have the following problem that I can't seem to solve. I have a database with 6 different tables. when I update the tables I have no problems expect with 1 table. I get a "the...
0
by: Tim::.. | last post by:
Can someone please help! I'm trying to write an insert statement for a complex datagrid! The database consists of the following data structure! ..tblContent PageID PK ModDate Description...
2
by: Polyhedron_12 | last post by:
I am having problems calling functions in general in VB. I keep getting alot of errors. Can anybody help me out with this? I put the error message on the same line that it says it is at. I believe...
4
by: David A. Osborn | last post by:
I am having problems with the following insert command: Me.OleDbInsertCommand1.CommandText = "INSERT INTO lutLookup(Type_Name, Work_Code, Work_Code_ID) VALUES ('Payment_ID',' " & _ lstrCode & "...
6
by: Eric Lilja | last post by:
Consider the following code: #include <iostream> #include <string> #include <vector> using namespace std; int main() {
5
by: Rob | last post by:
I'm trying to use the set<my_class>::insert( my_class const & ) method, but have run into some problems. It seems like I'm seeing it insert an object when a similar object is already in the set. ...
5
by: =?Utf-8?B?bXBhaW5l?= | last post by:
Hello, I am completely lost as to why I can't update a DropDownList inside a DetailsView after I perform an insert into an object datasource. I tried to simply it down to the core demostration:...
2
by: Terry Reedy | last post by:
SUBHABRATA, I recommend you study this excellent response carefully. castironpi wrote: It starts with a concrete test case -- an 'executable problem statement'. To me, this is cleared and...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

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.