I have a SQLite database which stores UUIDs as the keys. UUIDs are very long and so for usability I have implemented a function which autocompletes a UUID prefix to the full UUID value (or returns NULL on non-unique prefix).
I was wondering if there is a query which can return the set of UUID prefixes such that each prefix is unique. This includes two cases: the one where each UUID prefix is the smallest size it can possibly be and the case that all UUID prefixes are the length of the longest UUID prefix needed for uniqueness.
For example if the data is:
AB1234DE... AA1264DE... BA2234DE...
The set of minimal prefixes would be:
AB AA B
The set of prefixes with the length necessary for uniqueness:
AB AA BA
Any idea how to accomplish this in a SQLite query? (the column is named id)
This could be implemented using analytic functions that for example Oracle DBMS has, but in sqlite there is no way to write such complex logic in sql query.
The possible shorthand I could propose to use is:
And increase the length of string in your programming language until this query returns no rows (or you can even make nested query) like:
and increase substring length until
resultis not desired