Re: insert a dictionary into sql data base

2005-12-06 Thread David Bear
Carsten Haese wrote: > The > example he gave you constructs an insert query with only one parameter > placeholder. You'll need as many placeholders as the number of values that > are inserted. > > The following example should work better: > > def insertDict(curs, tablename, data): > fields = d

Re: insert a dictionary into sql data base

2005-12-05 Thread Carsten Haese
On Mon, 05 Dec 2005 18:00:21 -0700, David Bear wrote > Fredrik Lundh wrote: > > DON'T MANUALLY CONSTRUCT THE SQL INSERT STATEMENT. Use string > > formatting to insert the field names, but let the database layer deal with > > the values. > > > > If you want to do things in two steps, do the fields

Re: insert a dictionary into sql data base

2005-12-05 Thread David Bear
Fredrik Lundh wrote: > David Bear wrote > >> Fredrik Lundh wrote: >> >> > cursor.execute( >> > "INSERT INTO table (%s) VALUES (%%s);" % (",".join(fields)), >> > *values >> > ) >> >> Thanks for the hint. However, I don't understand the syntax. >> >> I will be inserting in to postgresql

Re: insert a dictionary into sql data base

2005-12-05 Thread David Bear
Fredrik Lundh wrote: > David Bear wrote > >> Fredrik Lundh wrote: >> >> > cursor.execute( >> > "INSERT INTO table (%s) VALUES (%%s);" % (",".join(fields)), >> > *values >> > ) >> >> Thanks for the hint. However, I don't understand the syntax. >> >> I will be inserting in to postgresql

Re: insert a dictionary into sql data base

2005-12-05 Thread Fredrik Lundh
David Bear wrote > Fredrik Lundh wrote: > > > cursor.execute( > > "INSERT INTO table (%s) VALUES (%%s);" % (",".join(fields)), > > *values > > ) > > Thanks for the hint. However, I don't understand the syntax. > > I will be inserting in to postgresql 8.x. I assumed the entire string wo

Re: insert a dictionary into sql data base

2005-12-05 Thread David Bear
Fredrik Lundh wrote: > cursor.execute( > "INSERT INTO table (%s) VALUES (%%s);" % (",".join(fields)), > *values > ) Thanks for the hint. However, I don't understand the syntax. I will be inserting in to postgresql 8.x. I assumed the entire string would be evaluated prior to being sen

Re: insert a dictionary into sql data base

2005-12-05 Thread Fredrik Lundh
David Bear wrote: > The dictionary keys are the field names. The values are the values to be > inserted. > > I am looking for a good pythonic way of expressing this, but I have a > problem with the way lists are represented when converted to strings. > > Lets say my dictionary is > > data = {"fnam