[web2py] Re: Getting only the latest "version" in a query of items with versions.

2016-08-22 Thread Niphlod
max(version_date) . group by item.id On Monday, August 22, 2016 at 9:52:55 AM UTC+2, Encompass solutions wrote: > > Consider the following pseudo model. > > item > ->name = "string" > > version > ->item_id = item.id > ->version_date = "datetime" > > > While I can easily create a collectio

[web2py] Re: Getting only the latest "version" in a query of items with versions.

2016-08-23 Thread Encompass solutions
This document doesn't mention your method or using max() http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#sum-avg-min-max-and-len Or I don't understand how you would do it. Could you provide greater detail on how to build that query? BR, Jason On Monday, August 22, 20

[web2py] Re: Getting only the latest "version" in a query of items with versions.

2016-08-23 Thread Niphlod
what you want is the latest version for each item_id . That is the row having the greatest version_date if you divide your dataset for each item_id. that is what groupby item_id does. and what max(version_date) does too. On Tuesday, August 23, 2016 at 11:05:52 AM UTC+2, Encompass solutions

[web2py] Re: Getting only the latest "version" in a query of items with versions.

2016-08-24 Thread Encompass solutions
Does this seem sensible? It seems to work with my initial tests. latest_versions = db( (db.item.id == db.item_version.artifact_id) & (db.item_version.id > 0) ).select(db.item.ALL,db.item_version.version_date.max(), groupby=db.item.id) the .ma

[web2py] Re: Getting only the latest "version" in a query of items with versions.

2016-08-24 Thread Dave S
On Wednesday, August 24, 2016 at 10:29:09 PM UTC-7, Encompass solutions wrote: > > Does this seem sensible? It seems to work with my initial tests. > > latest_versions = db( (db.item.id == db.item_version.artifact_id) & > (db.item_version.id > 0) >

[web2py] Re: Getting only the latest "version" in a query of items with versions.

2016-08-24 Thread Encompass solutions
Grr, And now I can't get the db.item_version.ALL without Postgresql panicking about not having the item in the group buy. How do I get the fields in the result set? Do I need to place it in as a belongs or something? latest_versions = db( (db.item.id == db.item_version.artifact_id) &

[web2py] Re: Getting only the latest "version" in a query of items with versions.

2016-08-24 Thread Encompass solutions
I suppose your right, but I was a little thrown, by the: max(variable_here) That was mentioned was not the solution at all, I kept looking for ways to use max as a function. My issue now, is that the group by doesn't like me getting all the tables I want in the return. BR, Jason Brower On Thursd

[web2py] Re: Getting only the latest "version" in a query of items with versions.

2016-08-25 Thread Niphlod
you're thinking with a human mind instead of thinking on how a database works... with sets of data. How can you ask a database to return a single set grouped by something and at the same time as for granular records??? When you use groupby, you can just ask for granular records of the columns