Replace ARRAY_ACCUM() custom function with ARRAY_AGG()

Tested each replacement to ensure that the return of NULL instead of
'{}' empty array doesn't break anything - although some functions didn't
seem to work with either function (for example,
asset.merge_record_assets() doesn't seem to actually move an 856 from
the source to the target record).

Also replace ARRAY_TO_STRING(ARRAY_AGG()) with STRING_AGG() in a couple
of places; see
http://www.depesz.com/index.php/2010/02/17/waiting-for-9-0-string_agg/
for one reason why (likely performance gain).

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Signed-off-by: Ben Shum <bshum@biblio.org>
Native SQL functions for Vandelay

Use STRING_AGG() where appropriate instead of
ARRAY_TO_STRING(ARRAY_ACCUM()), and ARRAY_AGG() instead of
ARRAY_ACCUM().

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Signed-off-by: Ben Shum <bshum@biblio.org>
One more STRING_AGG() conversion

Teach biblio.indexing_ingest_or_delete() to use STRING_AGG() where
appropriate.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Signed-off-by: Ben Shum <bshum@biblio.org>
Teach asset.merge_record_assets about STRING_AGG()

Now that asset.merge_record_assets() is working, cut over to
STRING_AGG() so it can iterate over those unnecessary nodes faster :)

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Signed-off-by: Ben Shum <bshum@biblio.org>
ARRAY_ACCUM() -> ARRAY_AGG() for new authority nfi functions

Fix the new places where array_accum() has been able to sneak into the
schema.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Signed-off-by: Ben Shum <bshum@biblio.org>
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 <dscott@laurentian.ca>
Signed-off-by: Ben Shum <bshum@biblio.org>
More native SQL functions

Found four more places that this needed to be changed.

Signed-off-by: Ben Shum <bshum@biblio.org>
Signed-off-by: Dan Scott <dscott@laurentian.ca>
Keep dropping and creating array_accum()

We want to keep array_accum() around for now to support any custom SQL that
sites might have generated. Plus, we don't want it to show up in our search
path ahead of the native array_agg()!

We can always rebase this as a fix into the previous commit to squash history a
bit. "Nope, that never happened!"

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Signed-off-by: Ben Shum <bshum@biblio.org>
Found a few last functions that need changing to native SQL

These new uses probably went in more recently as authority fixes. Updated them to
use the native functions as well.

Signed-off-by: Ben Shum <bshum@biblio.org>
Signed-off-by: Dan Scott <dscott@laurentian.ca>
Add upgrade script for changeover to array_agg() and string_agg()

Signed-off-by: Ben Shum <bshum@biblio.org>
Signed-off-by: Dan Scott <dscott@laurentian.ca>
Tweak STRING_AGG() arguments (expects TEXT or BYTEA)

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Sign off on upgrade script for (STRING|ARRAY)_AGG

Signed-off-by: Dan Scott <dscott@laurentian.ca>