pgstac icon indicating copy to clipboard operation
pgstac copied to clipboard

Syntax error from temporal_op_query

Open captaincoordinates opened this issue 1 year ago • 1 comments

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 avatar Jun 23 '24 22:06 captaincoordinates

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

captaincoordinates avatar Jun 25 '24 17:06 captaincoordinates