diff --git a/src/pg/sql/40_observatory_utility.sql b/src/pg/sql/40_observatory_utility.sql index 17e3d1e..19805c3 100644 --- a/src/pg/sql/40_observatory_utility.sql +++ b/src/pg/sql/40_observatory_utility.sql @@ -1,3 +1,16 @@ +-- In Postgis 3+, geomval is part of postgis_raster +-- Trying to workaround it by creating the type ourselves leads to other issues: +-- - If we create it under public, then if we try to create postgis_raster afterwards it will fail (ERROR: type "geomval" already exists). +-- - If we create it under cdb_observatory, then things work until we install postgis_raster. At that moment depending on how +-- the search_path is set (per call, function, user...) we start getting random errors since it's mixing public.geomval and +-- cdb_observatory.geomval (function cdb_observatory.obs_getdata(geomval[], json) does not exist) +DO $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'geomval') THEN + RAISE EXCEPTION 'Missing `geomval` type. Use `CREATE EXTENSION postgis_raster` to enable it.'; + END IF; +END$$; + -- Returns the table name with geoms for the given geometry_id -- TODO probably needs to take in the column_id array to get the relevant diff --git a/src/pg/sql/41_observatory_augmentation.sql b/src/pg/sql/41_observatory_augmentation.sql index b1c02dc..21067a8 100644 --- a/src/pg/sql/41_observatory_augmentation.sql +++ b/src/pg/sql/41_observatory_augmentation.sql @@ -516,8 +516,8 @@ BEGIN WHEN numer_id IS NULL THEN '''geomref'', ' || 'cdb_observatory.FIRST(' || geom_tablename || '.' || geom_geomref_colname || '), ' || - '''value'', ' || 'cdb_observatory.FIRST(' || geom_tablename || - '.' || geom_colname || ')' + '''value'', ' || '(cdb_observatory.FIRST(' || geom_tablename || + '.' || geom_colname || '))::TEXT' -- Needed to force text output in Postgis 3+, later parsed automagically by ::Geometry. Otherwise we'd get geojson output ELSE '' END || ')', ', ') AS colspecs,