LP#1400376: Don't allow NULL attrs to polute an HSTORE as a key
authorMike Rylander <mrylander@gmail.com>
Tue, 16 Dec 2014 01:32:51 +0000 (20:32 -0500)
committerBen Shum <bshum@biblio.org>
Tue, 16 Dec 2014 20:00:36 +0000 (15:00 -0500)
That causes the HSTORE to blow up, which is bad for circs that
want to succeed.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/src/sql/Pg/030.schema.metabib.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.no-null-record_attrs.sql [new file with mode: 0644]

index c03868e..58729d8 100644 (file)
@@ -421,7 +421,10 @@ CREATE VIEW metabib.record_attr_flat AS
             LEFT JOIN config.coded_value_map c ON ( c.id = ANY( v.vlist ) );
 
 CREATE VIEW metabib.record_attr AS
-    SELECT id, HSTORE( ARRAY_AGG( attr ), ARRAY_AGG( value ) ) AS attrs FROM metabib.record_attr_flat GROUP BY 1;
+    SELECT  id, HSTORE( ARRAY_AGG( attr ), ARRAY_AGG( value ) ) AS attrs
+      FROM  metabib.record_attr_flat
+      WHERE attr IS NOT NULL
+      GROUP BY 1;
 
 -- Back-back-compat view ... we use to live in an HSTORE world
 CREATE TYPE metabib.rec_desc_type AS (
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.no-null-record_attrs.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.no-null-record_attrs.sql
new file mode 100644 (file)
index 0000000..ee7f305
--- /dev/null
@@ -0,0 +1,10 @@
+BEGIN;
+
+CREATE OR REPLACE VIEW metabib.record_attr AS
+    SELECT  id, HSTORE( ARRAY_AGG( attr ), ARRAY_AGG( value ) ) AS attrs
+      FROM  metabib.record_attr_flat
+      WHERE attr IS NOT NULL
+      GROUP BY 1;
+
+COMMIT;
+