0

I'm working with a noSQL database and for certain reasons I can't use equality filtering in my queries

e.g

select all from database where id = 10 

is NOT allowed

but inequality filtering is allowed

e.g

select all from database where id > 1

My ID's are UNIQUE strings (emails) and I need to use equality filtering so I thought to convert inequality statements to equality statements (e.g where id = 10 could be written as Where id > 9 AND < 11).

If my ids were numbers I would use code such as this to get my key:

function(id)
{

    //assuming no id can be 0 and no id can be larger than 2^53-1. This will return the row with id = 10
    var result = sendToDatabaseQuery('SELECT * FROM database where id > ' + (id-1) + ' AND ' id < ' (i+1)');

}

With numbers it would be very easy to do this, but with Strings I have found it to be more challenging. If I have an email such as mysuperfakeemail.gmail.com how could I get the previous and next lexicographic string (I am assuming they are mysuperfakeemail.gmail.col and mysuperfakeemail.gmail.con respectively)? Is there an established algorithm for this type of function already? I am writing this on a nodejs server with UTF-8 characters.

Community
  • 1
  • 1
user2924127
  • 6,034
  • 16
  • 78
  • 136
  • When you say "NOT allowed" do you mean you get an error? Or is this some kind of assignment where you have to find a technique that avoids testing for equality? – BryanT Feb 05 '16 at 19:25
  • I am using Google's Datastore and for projection queries the properties used in filters cannot be in the projections. (https://cloud.google.com/datastore/docs/concepts/projectionqueries#Datastore_Limitations_on_projections). I need ID property to be in the projection and I also need to use the ID to filter by. – user2924127 Feb 05 '16 at 19:28
  • Got it. This is OK SELECT A FROM kind WHERE B = 1 and so is this SELECT A FROM kind WHERE A > 1 but this isn't SELECT A FROM kind WHERE A = 1 – BryanT Feb 05 '16 at 19:58
  • Yes and SELECT A FROM kind WHERE A = 1 is what I need to do but am not allowed. So I am trying to rewrite it as SELECT A FROM kind WHERE A > 0 and A < 2 – user2924127 Feb 05 '16 at 20:00
  • I hope I haven't over simplified this, but will this work? SELECT id FROM database WHERE id > "abc@def.com" ORDER BY id ASC LIMIT 1 SELECT id FROM database WHERE id < "abc@def.com" ORDER BY id DESC LIMIT 1 But I don't see that Google offers the "LIMIT" key word. Greater Than "string" works in SQL, subject to some problems with collating sequence and locale etc. – BryanT Feb 05 '16 at 20:20
  • That's two separate statments. – BryanT Feb 05 '16 at 20:20
  • Yes, I would like to only make one network call. – user2924127 Feb 05 '16 at 21:05

0 Answers0