I've got a table with a column of long geohash keys. My goal is to write a (Snowflake) SQL query to select those rows that match a set of bounding boxes. For the corner of each bounding box I have computed a short geohash (length dictated by the size of the bounding box).
I've deduplicated those bounding box geohash keys to improve efficiency. As a result there are no longer strictly 4 keys associated with each bounding box.
The goal would be a query that generates a table like the one below. The geohash and corner_keys columns are inputs and the within column is the output.
The corner_keys column is a list(varchar) datatype that I wish existed but probably doesn't.
geohash | corner_keys | within |
---|---|---|
9rv4a0nnq8 | 9rv,c4u | TRUE |
c4x99uq10x | 9rv,c4u | FALSE |
9rv4a0nnq8 | 9rx,9rq,9rm,9rv | TRUE |
c4x99uq10x | c4x | TRUE |
The SQL would look something like
any(startswith(geohash, corner_keys)) as within
How does one compare a geohash to a unspecified number of short keys?