From: Dan Scott Date: Tue, 3 Jan 2012 16:53:49 +0000 (-0500) Subject: Prevent {NULL} values from blocking bib saving X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=fc5bd43ec0fda187efa34b001b84ca6919b10f43;p=evergreen%2Fmasslnc.git Prevent {NULL} values from blocking bib saving With both the old ARRAY_ACCUM and ARRAY_AGG, and with array_nulls on, PostgreSQL 9.0 on Debian Squeeze was generating values of '{NULL}' rather than actual nulls. This would in turn prevent bibs without ISBNs or ISSNs from being saved successfully. A CASE statement protects against that problem and returns a clean NULL. Signed-off-by: Dan Scott Signed-off-by: Ben Shum --- diff --git a/Open-ILS/src/sql/Pg/reporter-schema.sql b/Open-ILS/src/sql/Pg/reporter-schema.sql index 70e24dad87..e8a3e55b65 100644 --- a/Open-ILS/src/sql/Pg/reporter-schema.sql +++ b/Open-ILS/src/sql/Pg/reporter-schema.sql @@ -158,8 +158,14 @@ SELECT r.id, FIRST(author.value) AS author, STRING_AGG(DISTINCT publisher.value, ', ') AS publisher, STRING_AGG(DISTINCT SUBSTRING(pubdate.value FROM $$\d+$$), ', ') AS pubdate, - ARRAY_AGG( DISTINCT REPLACE(SUBSTRING(isbn.value FROM $$^\S+$$), '-', '') ) AS isbn, - ARRAY_AGG( DISTINCT REGEXP_REPLACE(issn.value, E'^\\S*(\\d{4})[-\\s](\\d{3,4}x?)', E'\\1 \\2') ) AS issn + CASE WHEN ARRAY_AGG( DISTINCT REPLACE(SUBSTRING(isbn.value FROM $$^\S+$$), '-', '') ) = '{NULL}' + THEN NULL + ELSE ARRAY_AGG( DISTINCT REPLACE(SUBSTRING(isbn.value FROM $$^\S+$$), '-', '') ) + END AS isbn, + CASE WHEN ARRAY_AGG( DISTINCT REGEXP_REPLACE(issn.value, E'^\\S*(\\d{4})[-\\s](\\d{3,4}x?)', E'\\1 \\2') ) = '{NULL}' + THEN NULL + ELSE ARRAY_AGG( DISTINCT REGEXP_REPLACE(issn.value, E'^\\S*(\\d{4})[-\\s](\\d{3,4}x?)', E'\\1 \\2') ) + END AS issn FROM biblio.record_entry r LEFT JOIN metabib.full_rec title ON (r.id = title.record AND title.tag = '245' AND title.subfield = 'a') LEFT JOIN metabib.full_rec author ON (r.id = author.record AND author.tag IN ('100','110','111') AND author.subfield = 'a')