pg_featureserv icon indicating copy to clipboard operation
pg_featureserv copied to clipboard

Does pg_featureserv support JSONB fields?

Open donnyv opened this issue 2 years ago • 4 comments

I have a spatial table with a table id, geometry field, unique id field and a JSONB field for the rest of the data. Does pg_featureserv expand JSONB fields or would I have to create a View to do that?

donnyv avatar Jan 16 '24 15:01 donnyv

As far as I know pg_featureserv doesn't expand JSONB.

dr-jts avatar Mar 04 '24 22:03 dr-jts

Edit: my initial response was probably not directly helpful, as the question was about pg_tileserv rather than pg_featureserv.

MVT tiles

pg_tileserv constructs a SQL query that creates a tile using the ST_AsMVT comamnd in PostGIS. The PostGIS docs say:

The Mapbox Vector Tile format can store features with varying sets of attributes. To use this capability supply a JSONB column in the row data containing Json objects one level deep. The keys and values in the JSONB values will be encoded as feature attributes.

So with pg_tileserv, a JSONB field should be automatically expanded out to set multiple feature attributes.

GeoJSON

pg_featureserv uses the PostGIS function ST_AsGeoJSON, which acts differently: as JSON can represent nested data it doesn't do flattening. If you apply the function to data with a JSON column called data, the resulting features will have a property called data that has the same structure as the column (i.e., it will be an object). This is arguably more useful than automatically flattening data structures unnecessarily.

jamesscottbrown avatar Mar 07 '24 13:03 jamesscottbrown

@jamesscottbrown So can I search JSONB fields or not using pg_featureserv?

donnyv avatar Mar 11 '24 15:03 donnyv

@donnyv does this PR https://github.com/CrunchyData/pg_featureserv/pull/165 fix your issue?

JakobMiksch avatar Mar 31 '24 17:03 JakobMiksch