single iterations over duplicate values
I have a dtml method that accepts input from a zsql method and dtml-in is used to loop over the result set. However, there are duplicate values in the query result set(by design) but i want to list only one iteration of each value in my dtml method. Does anyone know how to do this, ie skip over duplicate results? regards garry
Probably the right thing to do is to fix the SQL query--look at the 'DISTINCT' option on the SELECT is probably what you want. On Sat, 3 Jan 2004, garry saddington wrote:
I have a dtml method that accepts input from a zsql method and dtml-in is used to loop over the result set. However, there are duplicate values in the query result set(by design) but i want to list only one iteration of each value in my dtml method. Does anyone know how to do this, ie skip over duplicate results? regards garry
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On Saturday 03 January 2004 20:26, Dennis Allison wrote:
Probably the right thing to do is to fix the SQL query--look at the 'DISTINCT' option on the SELECT is probably what you want.
The query must return duplicates so DISTINCT is not suitable, thanks anyway. regards garry
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
If the query is fast, you could do both and use the result from the one with the DISTINCT option for loop control and the other for processing. Alternatively, you could post process the query to create a list to use in the <dtml-in>. Take a look at the database interface system code in /home/zopesys/lib/python/Shared/DC/ZRDB. Applied to a SQL_query_result object, tuples() produces a list of of rows, dictionaries() produces a list of dictionaries with the column_names as keys. I assume you have one particular column that contains the values you are iterating. The following python script will return an appropriate list for <dtml-in>. The sort is optional. # Script (Python) "QueryIterationList" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=query, columnName ##title= ## dlist = Q.dictionaries() iterdict = {} for d in dlist: iterdict[d[columnName]]=1 iterlist = interdict.keys() return iterlist.sort() I've not checked this code so YMMV. You can do the same thing with tuples() and the columnIndex and gain a bit of speed. On Sat, 3 Jan Garry Saccington replied:
The query must return duplicates so DISTINCT is not suitable, thanks anyway.
On Sat, 3 Jan 2004, Dennis Allison wrote:
Probably the right thing to do is to fix the SQL query--look at the 'DISTINCT' option on the SELECT is probably what you want.
On Sat, 3 Jan 2004, garry saddington wrote:
I have a dtml method that accepts input from a zsql method and dtml-in is used to loop over the result set. However, there are duplicate values in the query result set(by design) but i want to list only one iteration of each value in my dtml method. Does anyone know how to do this, ie skip over duplicate results? regards garry
Take a look at <dtml-var first-xxx>. For example, if you the duplicate value you want to check for is named "test", you can check to see if the current iteration is the first iteration by using something like: <dtml-if first-test>. I think you need to sort the result set by the column you want to check. Kevin garry saddington wrote:
I have a dtml method that accepts input from a zsql method and dtml-in is used to loop over the result set. However, there are duplicate values in the query result set(by design) but i want to list only one iteration of each value in my dtml method. Does anyone know how to do this, ie skip over duplicate results? regards garry
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On Saturday 03 January 2004 20:34, Kevin Carlson wrote:
Take a look at <dtml-var first-xxx>. For example, if you the duplicate value you want to check for is named "test", you can check to see if the current iteration is the first iteration by using something like: <dtml-if first-test>.
I don't know what the duplicate is called could I just use sequence-item. regards garry
Use the column name returned from the query. I wasn't clear enough in my prior example: I meant to say if the column with duplicates is named "test"... Kevin garry saddington wrote:
On Saturday 03 January 2004 20:34, Kevin Carlson wrote:
Take a look at <dtml-var first-xxx>. For example, if you the duplicate value you want to check for is named "test", you can check to see if the current iteration is the first iteration by using something like: <dtml-if first-test>.
I don't know what the duplicate is called could I just use sequence-item. regards garry
participants (3)
-
Dennis Allison -
garry saddington -
Kevin Carlson