<html>
<body>
At 06:48 AM 6/2/2005, Greg Lindstrom wrote:<br>
<blockquote type=cite class=cite cite=""><font size=2>Hello-<br><br>
I am building a query to hit a Postgres (8.0.1) database from Python
(4.2.1) on Linux.&nbsp; Here's how I've been doing it for the past year
or so:<br><br>
data = {}<br>
data['start_date'] = '2005-6-2'<br>
data['last_name'] = 'Johnson'<br><br>
query = '''<br>
&nbsp;&nbsp; SELECT * <br>
&nbsp;&nbsp;&nbsp;&nbsp; FROM my_table<br>
&nbsp;&nbsp;&nbsp; WHERE date &gt;= '%(start_date)s'<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND last_name = '%(last_name)s'<br>
</font>''' % data<br>
results = my_database.Execute(query)<br><br>
and life has been good.&nbsp; What I would like to do now is use the
Postgres &quot;IN&quot; operator.&nbsp; For example:<br><br>
ids_to_process = ('1','2','3','5','7','11')<br><br>
I would like to get something akin to:<br><br>
query = '''<br>
&nbsp; UPDATE my_table <br>
&nbsp;&nbsp;&nbsp;&nbsp; SET state = 'processed' <br>
&nbsp;&nbsp; WHERE id IN ids_to_process<br>
'''</blockquote><br>
Do you want, in this case, the where clause to be : WHERE id IN&nbsp;
('1','2','3','5','7','11')?<br>
If so, how about:<br>
query = '''<br>
&nbsp; UPDATE my_table<br>
&nbsp;&nbsp;&nbsp; SET state = 'processed'<br>
&nbsp;&nbsp;&nbsp; WHERE id IN ''' + str(ids_to_process) <br><br>
<blockquote type=cite class=cite cite="">This would, of course, set the
'state' column to 'processed' for all of the ids in the list, but can not
figure out how to get this into a query to pass to the database.&nbsp;
Have any of you smart cookies out there dealt with this?&nbsp; There are
other ways to get the job done, worst case being writing a look and
issuing an UPDATE for each id, but that is not too elegant,
IMHO.<br><br>
Any help or pointers would be greatly appreciated,<br><br>
--greg<br>
_______________________________________________<br>
Tutor maillist&nbsp; -&nbsp; Tutor@python.org<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" eudora="autourl">http://mail.python.org/mailman/listinfo/tutor</a></blockquote>
<x-sigsep><p></x-sigsep>
<font size=2>Bob Gailer<br>
<a href="mailto:bgailer@alum.rpi.edu" eudora="autourl">mailto:bgailer@alum.rpi.edu<br>
</a>510 558 3275 home<br>
720 938 2625 cell</font> </body>
</html>