-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename variable to make pgstac compatible with pg>=14 (#151)
* rename variable to make pgstac compatible with pg>=14 * update tests * add table change to migration, change version to 0.6.11 * update changelog Co-authored-by: David Bitner <[email protected]>
- Loading branch information
1 parent
a140e1e
commit da8d693
Showing
16 changed files
with
3,103 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
SET SEARCH_PATH to pgstac, public; | ||
set check_function_bodies = off; | ||
|
||
UPDATE pgstac_settings SET name='default_filter_lang' WHERE name='default-filter-lang'; | ||
|
||
CREATE OR REPLACE FUNCTION pgstac.stac_search_to_where(j jsonb) | ||
RETURNS text | ||
LANGUAGE plpgsql | ||
STABLE | ||
AS $function$ | ||
DECLARE | ||
where_segments text[]; | ||
_where text; | ||
dtrange tstzrange; | ||
collections text[]; | ||
geom geometry; | ||
sdate timestamptz; | ||
edate timestamptz; | ||
filterlang text; | ||
filter jsonb := j->'filter'; | ||
BEGIN | ||
IF j ? 'ids' THEN | ||
where_segments := where_segments || format('id = ANY (%L) ', to_text_array(j->'ids')); | ||
END IF; | ||
|
||
IF j ? 'collections' THEN | ||
collections := to_text_array(j->'collections'); | ||
where_segments := where_segments || format('collection = ANY (%L) ', collections); | ||
END IF; | ||
|
||
IF j ? 'datetime' THEN | ||
dtrange := parse_dtrange(j->'datetime'); | ||
sdate := lower(dtrange); | ||
edate := upper(dtrange); | ||
|
||
where_segments := where_segments || format(' datetime <= %L::timestamptz AND end_datetime >= %L::timestamptz ', | ||
edate, | ||
sdate | ||
); | ||
END IF; | ||
|
||
geom := stac_geom(j); | ||
IF geom IS NOT NULL THEN | ||
where_segments := where_segments || format('st_intersects(geometry, %L)',geom); | ||
END IF; | ||
|
||
filterlang := COALESCE( | ||
j->>'filter-lang', | ||
get_setting('default_filter_lang', j->'conf') | ||
); | ||
IF NOT filter @? '$.**.op' THEN | ||
filterlang := 'cql-json'; | ||
END IF; | ||
|
||
IF filterlang NOT IN ('cql-json','cql2-json') AND j ? 'filter' THEN | ||
RAISE EXCEPTION '% is not a supported filter-lang. Please use cql-json or cql2-json.', filterlang; | ||
END IF; | ||
|
||
IF j ? 'query' AND j ? 'filter' THEN | ||
RAISE EXCEPTION 'Can only use either query or filter at one time.'; | ||
END IF; | ||
|
||
IF j ? 'query' THEN | ||
filter := query_to_cql2(j->'query'); | ||
ELSIF filterlang = 'cql-json' THEN | ||
filter := cql1_to_cql2(filter); | ||
END IF; | ||
RAISE NOTICE 'FILTER: %', filter; | ||
where_segments := where_segments || cql2_query(filter); | ||
IF cardinality(where_segments) < 1 THEN | ||
RETURN ' TRUE '; | ||
END IF; | ||
|
||
_where := array_to_string(array_remove(where_segments, NULL), ' AND '); | ||
|
||
IF _where IS NULL OR BTRIM(_where) = '' THEN | ||
RETURN ' TRUE '; | ||
END IF; | ||
RETURN _where; | ||
|
||
END; | ||
$function$ | ||
; | ||
|
||
|
||
|
||
SELECT set_version('0.6.11'); |
Oops, something went wrong.