0

I'm trying to stop duplicates of a database entity called "Post" in my program. In order to do this I want to append a number like "1" or "2" next to it. In other words:

helloworld helloworld1 helloworld2

In order to do this I need to query the database for postid's starting with helloworld. I read that GQL doesn't support the LIKE operation, so what can I do instead?

Thanks!

user2200321
  • 325
  • 1
  • 4
  • 18
  • 1
    Every datastore entity has an unique key. So what is the problem? If you do not assign a key yousef, the datastore will provide one (id). – voscausa Apr 14 '14 at 23:06

2 Answers2

0

Could you make the number a separate field? Then you won't have to search for prefix.

Isaac
  • 758
  • 5
  • 16
  • Yes, but on what condition would I increment the number? – user2200321 Apr 14 '14 at 22:47
  • You could use a [Counter](https://developers.google.com/appengine/articles/sharding_counters) or encode both fields into the key and query for highest entry. – Isaac Apr 16 '14 at 21:25
0

There is no LIKE.

Based on your criteria the closest you can achieve will be a query using the '>' and '<' operators.

select * from Post where postid > "helloworld" and postid < "helloworld9999" for instance.

I don't really understand what you are trying to do, so there may well be a better approach, maybe you can elaborate your use case.

Tim Hoffman
  • 12,976
  • 1
  • 17
  • 29