stac-utils / pgstac

Schema, functions and a python library for storing and accessing STAC collections and items in PostgreSQL
MIT License
133 stars 30 forks source link

Syntax error from temporal_op_query #281

Open captaincoordinates opened 1 week ago

captaincoordinates commented 1 week ago

Given what I believe to be a valid temporal filter, pgstac's temporal_op_query function appears to generate invalid SQL which raises a syntax error. This may simply be a case of me misunderstanding how to execute the function, so any additional information would be very much appreciated. I'm really struggling to find comprehensive documentation on temporal filters.

The following query's temporal operator is translated to an SQL construct here. However it appears that AND rl < lh < rh is invalid SQL, and should in fact be AND rl < lh AND lh < rh.

SELECT search('{
    "filter": {
        "op": "t_overlaps",
        "args": [
            "2011-08-16T00:00:00Z/2011-08-17T00:00:00Z"
        ]
    }
}')
ERROR:  syntax error at or near "<"
LINE 1: ...6 00:00:00+00'::timestamptz AND rl < end_datetime < '2011-08...
QUERY:  EXPLAIN (format json) SELECT 1 FROM items WHERE (datetime < '2011-08-16 00:00:00+00'::timestamptz AND rl < end_datetime < '2011-08-17 00:00:00+00'::timestamptz);

Because of challenges around documentation I'm not sure if this is the right way to perform t_overlaps. The extension documentation only provides an example of an intersection and from what I can gather pgstac's unit tests only address t_intersects, t_after, and t_before operators.

captaincoordinates commented 5 days ago

I'm also interested in learning more about the reasoning around temporal operator SQL statements. From what I can tell pgstac disregards any property provided in the JSON filter and always targets datetime and end_datetime