2

Hello I have this on my GAE application:

try:
    last = RegistroDescargas.gql("order by date DESC LIMIT 4")
except:
    last = None

With that I can get the last four rows of the database ("RegistroDescagas") that is defined as follows:

class RegistroDescargas(db.Model):
    '''Model para guardar el registro de vídeos descargados en la web'''
    date = db.DateTimeProperty(auto_now_add=True)
    urlOrig = db.StringProperty(required=True)
    urlImg = db.StringProperty(required=True)
    vidTit = db.StringProperty(required=True)
    vidDesc = db.TextProperty()

But of course, if one or the last four results are repeated, just shows me and what I want is to get the last not repeated four rows, and I do not know how I can do that...

Any suggestions? (I think, if at the end this is possible, could be with a totally different sentence, but I don't mind ;))

Any help much appreciated.. Sorry for my english..

aabilio
  • 1,697
  • 12
  • 19

2 Answers2

1

GQL does not support DISTINCT queries. The closet you can do is put the results into a set and check how many entries are in a set. If less than four, query for additional records.

This answer is more in depth: Python: DISTINCT on GQuery result set (GQL, GAE)

Otherwise, such distinct list need to be pre-computed. GAE follows a mantra of expensive writes to enable super-fast reads.

Community
  • 1
  • 1
Sologoub
  • 5,312
  • 6
  • 37
  • 65
  • Thank you very much for your answer. I'll try something like put the results into a set (I need date ordered result). You have given me a good idea, thanks ;) – aabilio Jan 04 '13 at 05:16
  • 1
    In order to save money, try this pattern: `a) get last four results; use a set with the key you want to be unique b) while results < 4 c) run a query for one entity on unique_property < lowest_value d) if you run out of results early, just break and return` – Ajax Jan 04 '13 at 11:21
0

The DISTINCT keyword was introduced in release 1.7.4..

You can find the updated GQL reference (for example for Python) here.

Bernd Verst
  • 836
  • 8
  • 12