]> granicus.if.org Git - postgis/commitdiff
AddRasterConstraints: Ignore NULLs when generating constraints
authorRaúl Marín Rodríguez <rmrodriguez@carto.com>
Wed, 12 Jun 2019 13:31:25 +0000 (13:31 +0000)
committerRaúl Marín Rodríguez <rmrodriguez@carto.com>
Wed, 12 Jun 2019 13:31:25 +0000 (13:31 +0000)
Closes #4388

git-svn-id: http://svn.osgeo.org/postgis/branches/2.3@17514 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
raster/rt_pg/rtpostgis.sql.in
raster/test/regress/tickets.sql
raster/test/regress/tickets_expected

diff --git a/NEWS b/NEWS
index 408c43c17ff6e6e852626f8b4b3f406a841bf6d0..db4833045a8b75871fb22352f2d96bb7e69898fa 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ PostGIS 2.3.10
 
   - #4361, Fix postgis_type_name with (GEOMETRYM,3) (Matt Bretl)
   - #4326, Fix circular arc distance calculation (Paul Ramsey)
+  - #4388, AddRasterConstraints: Ignore NULLs when generating constraints (Raúl Marín)
 
 
 PostGIS 2.3.9
index ff9b6bdbbddd34d4edfd32c900919b939e948827..5537d654c071e78982f99c134388029e4faa7d76 100644 (file)
@@ -6919,7 +6919,9 @@ CREATE OR REPLACE FUNCTION _add_raster_constraint_srid(rastschema name, rasttabl
                sql := 'SELECT st_srid('
                        || quote_ident($3)
                        || ') FROM ' || fqtn
-                       || ' LIMIT 1';
+                       || ' WHERE '
+                       || quote_ident($3)
+                       || ' IS NOT NULL LIMIT 1;';
                BEGIN
                        EXECUTE sql INTO attr;
                EXCEPTION WHEN OTHERS THEN
@@ -7000,7 +7002,9 @@ CREATE OR REPLACE FUNCTION _add_raster_constraint_scale(rastschema name, rasttab
                        || quote_ident($3)
                        || ') FROM '
                        || fqtn
-                       || ' LIMIT 1';
+                       || ' WHERE '
+                       || quote_ident($3)
+                       || ' IS NOT NULL LIMIT 1;';
                BEGIN
                        EXECUTE sql INTO attr;
                EXCEPTION WHEN OTHERS THEN
@@ -7147,11 +7151,13 @@ CREATE OR REPLACE FUNCTION _add_raster_constraint_extent(rastschema name, rastta
                fqtn := fqtn || quote_ident($2);
 
                sql := 'SELECT @extschema@.ST_SRID('
-            || quote_ident($3)
-      || ') FROM '
-            || fqtn
-            || ' LIMIT 1;';
-    EXECUTE sql INTO srid;
+                       || quote_ident($3)
+                       || ') FROM '
+                       || fqtn
+                       || ' WHERE '
+                       || quote_ident($3)
+                       || ' IS NOT NULL LIMIT 1;';
+                EXECUTE sql INTO srid;
 
                cn := 'enforce_max_extent_' || $3;
 
@@ -7212,7 +7218,11 @@ CREATE OR REPLACE FUNCTION _add_raster_constraint_alignment(rastschema name, ras
 
                sql := 'SELECT @extschema@.st_makeemptyraster(1, 1, upperleftx, upperlefty, scalex, scaley, skewx, skewy, srid) FROM @extschema@.st_metadata((SELECT '
                        || quote_ident($3)
-                       || ' FROM ' || fqtn || ' LIMIT 1))';
+                       || ' FROM '
+                       || fqtn
+                       || ' WHERE '
+                       || quote_ident($3)
+                       || ' IS NOT NULL LIMIT 1))';
                BEGIN
                        EXECUTE sql INTO attr;
                EXCEPTION WHEN OTHERS THEN
@@ -7450,8 +7460,11 @@ CREATE OR REPLACE FUNCTION _add_raster_constraint_num_bands(rastschema name, ras
                cn := 'enforce_num_bands_' || $3;
 
                sql := 'SELECT @extschema@.st_numbands(' || quote_ident($3)
-                       || ') FROM ' || fqtn
-                       || ' LIMIT 1';
+                       || ') FROM '
+                       || fqtn
+                       || ' WHERE '
+                       || quote_ident($3)
+                       || ' IS NOT NULL LIMIT 1;';
                BEGIN
                        EXECUTE sql INTO attr;
                EXCEPTION WHEN OTHERS THEN
@@ -7524,7 +7537,9 @@ CREATE OR REPLACE FUNCTION _add_raster_constraint_pixel_types(rastschema name, r
 
                sql := 'SELECT @extschema@._raster_constraint_pixel_types(' || quote_ident($3)
                        || ') FROM ' || fqtn
-                       || ' LIMIT 1';
+                       || ' WHERE '
+                       || quote_ident($3)
+                       || ' IS NOT NULL LIMIT 1;';
                BEGIN
                        EXECUTE sql INTO attr;
                EXCEPTION WHEN OTHERS THEN
@@ -7608,7 +7623,9 @@ CREATE OR REPLACE FUNCTION _add_raster_constraint_nodata_values(rastschema name,
 
                sql := 'SELECT @extschema@._raster_constraint_nodata_values(' || quote_ident($3)
                        || ') FROM ' || fqtn
-                       || ' LIMIT 1';
+                       || ' WHERE '
+                       || quote_ident($3)
+                       || ' IS NOT NULL LIMIT 1;';
                BEGIN
                        EXECUTE sql INTO attr;
                EXCEPTION WHEN OTHERS THEN
@@ -7695,7 +7712,9 @@ CREATE OR REPLACE FUNCTION _add_raster_constraint_out_db(rastschema name, rastta
 
                sql := 'SELECT @extschema@._raster_constraint_out_db(' || quote_ident($3)
                        || ') FROM ' || fqtn
-                       || ' LIMIT 1';
+                       || ' WHERE '
+                       || quote_ident($3)
+                       || ' IS NOT NULL LIMIT 1;';
                BEGIN
                        EXECUTE sql INTO attr;
                EXCEPTION WHEN OTHERS THEN
index 4a62cb3b320f2b514c196c2c2e035675a1d1b916..5501ebb8932ee4c17202ac52b71a9e59344e9426 100644 (file)
@@ -117,3 +117,12 @@ SET client_min_messages TO DEFAULT;
  #3055 ST_Clip() on a raster without band crashes the server
 ******************************************************************************/
 SELECT ST_SummaryStats(ST_Clip(ST_MakeEmptyRaster(42, 42, 0, 0, 1.0, 1.0, 0, 0, 4269), ST_MakeEnvelope(0, 0, 20, 20, 4269)));
+
+/**
+#4308,
+*/
+CREATE TABLE table_4308 (r raster);
+INSERT INTO table_4308(r) values (NULL);
+INSERT INTO table_4308(r) SELECT ST_AddBand(ST_MakeEmptyRaster(10, 10, 1, 1, 2, 2, 0, 0,4326), 1, '8BSI'::text, -129, NULL);;
+SELECT AddRasterConstraints('table_4308', 'r');
+DROP TABLE table_4308;
\ No newline at end of file
index de6373b22e03f438c4be8be96375a906f1118b68..31ff4d4f684d625ed7a80bf2de3fcee4cc37b06e 100644 (file)
@@ -14,3 +14,15 @@ test_raster_scale_small|rast||1
 ERROR:  new row for relation "test_raster_scale_small" violates check constraint "enforce_scaley_rast"
 NOTICE:  Input raster is empty or has no bands. Returning empty raster
 NOTICE:  Invalid band index (must use 1-based). Returning NULL
+NOTICE:  Adding SRID constraint
+NOTICE:  Adding scale-X constraint
+NOTICE:  Adding scale-Y constraint
+NOTICE:  Adding blocksize-X constraint
+NOTICE:  Adding blocksize-Y constraint
+NOTICE:  Adding alignment constraint
+NOTICE:  Adding number of bands constraint
+NOTICE:  Adding pixel type constraint
+NOTICE:  Adding nodata value constraint
+NOTICE:  Adding out-of-database constraint
+NOTICE:  Adding maximum extent constraint
+t