Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102316 > unrolled thread
| Started by | Michael Torrie <torriem@gmail.com> |
|---|---|
| First post | 2016-01-30 15:05 -0700 |
| Last post | 2016-01-31 11:50 +1300 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Cannot step through asynchronous iterator manually Michael Torrie <torriem@gmail.com> - 2016-01-30 15:05 -0700
Re: Cannot step through asynchronous iterator manually Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-01-31 11:50 +1300
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2016-01-30 15:05 -0700 |
| Subject | Re: Cannot step through asynchronous iterator manually |
| Message-ID | <mailman.142.1454191515.2338.python-list@python.org> |
On 01/30/2016 02:57 PM, Michael Torrie wrote: > SELECT count(some_id_field),field1,field2,field3 FROM wherever WHERE > conditions > > If the first column (or whatever you decide to alias it as) contains a > count, and the rest of the information is still there. If count is 1, > then the row is what you want and you can do whatever you wish with it. > If not, throw your exception. I'm not sure how SQLite handles it, or even what the SQL spec says, but I know in MySQL you could do something like this: SELECT count(id) as row_count,`tablename`.* FROM `tablename` WHERE condition and get the same thing as SELECT * would have, with the addition of a "row_count" field. Note that because of the count() part, the query will always only return 1 row. The fields will be NULL if the count was zero or they will contain the fields from the last row the query found. In other words if there is more than one row that matches the query, it will only give you data from the last match. Now if Frank is hoping to do work on the first row and then throw an exception if there's an additional row, then this of course won't work for him.
[toc] | [next] | [standalone]
| From | Gregory Ewing <greg.ewing@canterbury.ac.nz> |
|---|---|
| Date | 2016-01-31 11:50 +1300 |
| Message-ID | <dh4t2iFjpnrU1@mid.individual.net> |
| In reply to | #102316 |
Michael Torrie wrote: > I'm not sure how SQLite handles it, or even what the SQL spec says, but > I know in MySQL you could do something like this: > > SELECT count(id) as row_count,`tablename`.* FROM `tablename` WHERE condition I don't think that's strictly valid SQL. I know of at least one SQL implementation that complains if you have fields in an aggregate query that aren't either in an aggregate function or listed in the GROUP BY clause. To make it valid you would have to wrap LAST() around all of the other fields. (Probably individually -- I doubt whether LAST(tablename.*) would be accepted.) Which seems like a lot of trouble to go to just to tell whether you have a unique result. Also it's asking the DB to perform more work than you really need. It has to run the whole query before returning any results, whereas doing it yourself you can give up after reading the second result if there is one. -- Greg
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web