Thursday 15 August 2013

sql - Limit results to x groups -


I am developing a system using Trek, and I want to limit the number of "changelog" entries . The point is that Trac connects these entries with several tables using a union , and later adds them into single 'changes' based on their timestamp. I want to limit the results to the latest I 3 changes, but I need to recover several rows until it is needed unless I have 3 unique timestamps. Solution needs to work for SQLite / Postgres.

Current SQL Results

  NEWVALUE Permanent OLDVALUE Time User Field ========== ================================================== =========== 1371806593507544 1 1371806593507544 A comment 2 lipsum bc One owner 1 1371806593507544 Description foo times 1 1371806593324529 b Comment Hello world 1 1371806593125677 c Priority minor minor 1 1371806592492812 d comment xy 1   

SQL results (like 1 timestamp to be limited) with intent

  time nEWVALUE lasting == OLDVALUE User field ======= ==== ================================================= ======== 1371806593507544 1 1371806593507544 One Comment 2 lipsum 1 1371806593507544 Description foo bar 1    

As you've already said on your own, this result can not be solved in SQL due to an indefinite number of results. And I think that this is also not necessary.

You can use a slightly modified template to get what you want. Change

  & lt; Div id = "changelog" & gt; & Lt; Py: Each = "Changes in Changes" & gt;   

In

  & lt; Div id = "changelog" & gt; & Lt; Py: Each = "Changes in Changes [-3:]" & gt;   

and the file should be and lt; Env & gt; Restart your web-server in / template / but look for a change of ticket, whenever you try to upgrade your track's upgrade. Each time you do this, you may need to re-apply this change to the current template of the related edition. But the IMHO track core code is still much faster and cleaner than the patch.

No comments:

Post a Comment