Skip to content

Commit da8d693

Browse files
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]>
1 parent a140e1e commit da8d693

16 files changed

+3103
-24
lines changed

CHANGELOG.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
6+
7+
## [v0.6.11]
8+
9+
### Fixed
10+
- update pypgstac requirements to support python 3.11 [142](https://github.com/stac-utils/pgstac/pull/142)
11+
- rename pgstac setting `default-filter-lang` to `default_filter_lang` to allow pgstac on postgresql>=14
12+
613
## [v0.6.10]
714

815
### Fixed
@@ -17,24 +24,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1724

1825
### Added
1926
- Add get_queryables function to return a composite queryables json for either a single collection (text), a list of collections(text[]), or for the full repository (null::text).
20-
2127
- Add missing_queryables(collection text, tablesample int) function to help identify if there are any properties in a collection without entries in the queryables table. The tablesample parameter is an int <=100 that is the approximate percentage of the collection to scan to look for missing queryables rather than reading every item.
22-
2328
- Add missing_queryables(tablesample int) function that scans all collections using a sample of records to identify missing queryables.
2429

25-
26-
2730
## [v0.6.7]
2831

2932
### Added
3033
- Add get_queryables function to return a composite queryables json for either a single collection (text), a list of collections(text[]), or for the full repository (null::text).
31-
3234
- Add missing_queryables(collection text, tablesample int) function to help identify if there are any properties in a collection without entries in the queryables table. The tablesample parameter is an int <=100 that is the approximate percentage of the collection to scan to look for missing queryables rather than reading every item.
33-
3435
- Add missing_queryables(tablesample int) function that scans all collections using a sample of records to identify missing queryables.
3536

36-
37-
3837
## [v0.6.6]
3938

4039
### Added
@@ -236,7 +235,9 @@ _TODO_
236235

237236
- Fixed issue with pypgstac loads which caused some writes to fail ([#18](https://github.com/stac-utils/pgstac/pull/18))
238237

239-
[unreleased]: https://github.com/stac-utils/pgstac/compare/v0.6.8...HEAD
238+
[unreleased]: https://github.com/stac-utils/pgstac/compare/v0.6.10...HEAD
239+
[v0.6.10]: https://github.com//stac-utils/pgstac/compare/v0.6.9...v0.6.10
240+
[v0.6.9]: https://github.com//stac-utils/pgstac/compare/v0.6.8...v0.6.9
240241
[v0.6.8]: https://github.com//stac-utils/pgstac/compare/v0.6.7...v0.6.8
241242
[v0.6.7]: https://github.com//stac-utils/pgstac/compare/v0.6.6...v0.6.7
242243
[v0.6.6]: https://github.com//stac-utils/pgstac/compare/v0.6.5...v0.6.6
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
SET SEARCH_PATH to pgstac, public;
2+
set check_function_bodies = off;
3+
4+
UPDATE pgstac_settings SET name='default_filter_lang' WHERE name='default-filter-lang';
5+
6+
CREATE OR REPLACE FUNCTION pgstac.stac_search_to_where(j jsonb)
7+
RETURNS text
8+
LANGUAGE plpgsql
9+
STABLE
10+
AS $function$
11+
DECLARE
12+
where_segments text[];
13+
_where text;
14+
dtrange tstzrange;
15+
collections text[];
16+
geom geometry;
17+
sdate timestamptz;
18+
edate timestamptz;
19+
filterlang text;
20+
filter jsonb := j->'filter';
21+
BEGIN
22+
IF j ? 'ids' THEN
23+
where_segments := where_segments || format('id = ANY (%L) ', to_text_array(j->'ids'));
24+
END IF;
25+
26+
IF j ? 'collections' THEN
27+
collections := to_text_array(j->'collections');
28+
where_segments := where_segments || format('collection = ANY (%L) ', collections);
29+
END IF;
30+
31+
IF j ? 'datetime' THEN
32+
dtrange := parse_dtrange(j->'datetime');
33+
sdate := lower(dtrange);
34+
edate := upper(dtrange);
35+
36+
where_segments := where_segments || format(' datetime <= %L::timestamptz AND end_datetime >= %L::timestamptz ',
37+
edate,
38+
sdate
39+
);
40+
END IF;
41+
42+
geom := stac_geom(j);
43+
IF geom IS NOT NULL THEN
44+
where_segments := where_segments || format('st_intersects(geometry, %L)',geom);
45+
END IF;
46+
47+
filterlang := COALESCE(
48+
j->>'filter-lang',
49+
get_setting('default_filter_lang', j->'conf')
50+
);
51+
IF NOT filter @? '$.**.op' THEN
52+
filterlang := 'cql-json';
53+
END IF;
54+
55+
IF filterlang NOT IN ('cql-json','cql2-json') AND j ? 'filter' THEN
56+
RAISE EXCEPTION '% is not a supported filter-lang. Please use cql-json or cql2-json.', filterlang;
57+
END IF;
58+
59+
IF j ? 'query' AND j ? 'filter' THEN
60+
RAISE EXCEPTION 'Can only use either query or filter at one time.';
61+
END IF;
62+
63+
IF j ? 'query' THEN
64+
filter := query_to_cql2(j->'query');
65+
ELSIF filterlang = 'cql-json' THEN
66+
filter := cql1_to_cql2(filter);
67+
END IF;
68+
RAISE NOTICE 'FILTER: %', filter;
69+
where_segments := where_segments || cql2_query(filter);
70+
IF cardinality(where_segments) < 1 THEN
71+
RETURN ' TRUE ';
72+
END IF;
73+
74+
_where := array_to_string(array_remove(where_segments, NULL), ' AND ');
75+
76+
IF _where IS NULL OR BTRIM(_where) = '' THEN
77+
RETURN ' TRUE ';
78+
END IF;
79+
RETURN _where;
80+
81+
END;
82+
$function$
83+
;
84+
85+
86+
87+
SELECT set_version('0.6.11');

0 commit comments

Comments
 (0)