%s place holder does not let me insert ' in an sql query with python.

2008-12-15 Thread Krishnakant
hello all hackers. This is some kind of an interesting situation although many of you must have already gone through it. I am facing a situation where I have to use psycopg2 and insert rows in a postgresql table. That's pritty easy and no need to say that it works well. But there are some entries

Re: %s place holder does not let me insert ' in an sql query with python.

2008-12-15 Thread Lamonte Harris
sorry about that queryString = "insert into venders values('{0}','{1}','{2}')".format(field1,field2,field3) On Mon, Dec 15, 2008 at 7:21 AM, Lamonte Harris wrote: > I had this problem too. If you've upgraded to python 2.6 you need to use > the new sytnax "format > > queryString = "insert into v

Re: %s place holder does not let me insert ' in an sql query with python.

2008-12-15 Thread Lamonte Harris
I had this problem too. If you've upgraded to python 2.6 you need to use the new sytnax "format queryString = "insert into venders values('{0}','{1}','{2}'".format(field1,field2,field3) On Mon, Dec 15, 2008 at 6:46 AM, Krishnakant wrote: > hello all hackers. > This is some kind of an interesti

Re: %s place holder does not let me insert ' in an sql query with python.

2008-12-15 Thread Joe Strout
On Dec 15, 2008, at 6:46 AM, Krishnakant wrote: in this case, I get a problem when there is ' in any of the values during insert or update. That's because ' is the SQL string literal delimiter. But any SQL- compliant database allows you to "escape" an apostrophe within a string literal by

Re: %s place holder does not let me insert ' in an sql query with python.

2008-12-15 Thread Paul Boddie
On 15 Des, 14:46, Krishnakant wrote: > hello all, > thanks for all of your very quick responses. > The problem is that I am using python 2.5 so the 2.6 syntax does not > apply in my case. The parameter syntax for database operations is defined by the DB-API, and this is a very different matter to

Re: %s place holder does not let me insert ' in an sql query with python.

2008-12-15 Thread Jean-Paul Calderone
On Mon, 15 Dec 2008 18:16:18 +0530, Krishnakant wrote: hello all hackers. This is some kind of an interesting situation although many of you must have already gone through it. I am facing a situation where I have to use psycopg2 and insert rows in a postgresql table. That's pritty easy and no ne

Re: %s place holder does not let me insert ' in an sql query with python.

2008-12-15 Thread rdmurray
On Mon, 15 Dec 2008 at 18:16, Krishnakant wrote: how do you let the ' go as a part of the string? I have used %s as placeholder as in queryString = "insert into venders values ('%s,%s,%s" % (field1,field2,field3 ) ... This is not working for the ' values. This is untested, but I think what you

Re: %s place holder does not let me insert ' in an sql query with python.

2008-12-15 Thread Krishnakant
hello all, thanks for all of your very quick responses. The problem is that I am using python 2.5 so the 2.6 syntax does not apply in my case. secondly, My problem is very unique. I have created a function called executeProcedure in python which calls stored procedures in postgresql. The fun part o

Re: %s place holder does not let me insert ' in an sql query with python.

2008-12-15 Thread Steve Holden
Lamonte Harris wrote: > I had this problem too. If you've upgraded to python 2.6 you need to > use the new sytnax "format > > queryString = "insert into venders > values('{0}','{1}','{2}'".format(field1,field2,field3) > Will all readers of this thread kindly regard this as an example of how *not

Re: %s place holder does not let me insert ' in an sql query with python.

2008-12-15 Thread Krishnakant
Hi steve. you are right. Thanks for all you who helped to understand how to and *not* to pass queries through psycopg2 which is a module based on python dbapi. the following query worked. cursor.execute("insert into vendors values(%s,%s)", lstParams) lstParams contained all the values and yes one h

Re: %s place holder does not let me insert ' in an sql query with python.

2008-12-15 Thread Bruno Desthuilliers
Joe Strout a écrit : On Dec 15, 2008, at 6:46 AM, Krishnakant wrote: in this case, I get a problem when there is ' in any of the values during insert or update. That's because ' is the SQL string literal delimiter. But any SQL-compliant database allows you to "escape" an apostrophe within a