$table cn
where
not deleted
- and (cast(upper(label) as bytea) > ? or ( cn.id > ? and cast(upper(label) as bytea) = ? ))
+ and (oils_text_as_bytea(upper(label)) > ? or ( cn.id > ? and oils_text_as_bytea(upper(label)) = ? ))
and owning_lib in ($orgs)
- order by cast(upper(label) as bytea), 4, 2
+ order by oils_text_as_bytea(upper(label)), 4, 2
limit $size;
SQL
$table cn
where
not deleted
- and (cast(upper(label) as bytea) < ? or ( cn.id < ? and cast(upper(label) as bytea) = ? ))
+ and (oils_text_as_bytea(upper(label)) < ? or ( cn.id < ? and oils_text_as_bytea(upper(label)) = ? ))
and owning_lib in ($orgs)
- order by cast(upper(label) as bytea) desc, 4 desc, 2 desc
+ order by oils_text_as_bytea(upper(label)) desc, 4 desc, 2 desc
limit $size
) as bar
order by 1,4,2;
$table cn
where
not deleted
- and cast(upper(label) as bytea) < ?
+ and oils_text_as_bytea(upper(label)) < ?
and owning_lib in ($orgs)
- order by cast(upper(label) as bytea) desc, 4 desc, 2 desc
+ order by oils_text_as_bytea(upper(label)) desc, 4 desc, 2 desc
limit $topsize
) as bar
order by 1,4,2;
$table cn
where
not deleted
- and cast(upper(label) as bytea) >= ?
+ and oils_text_as_bytea(upper(label)) >= ?
and owning_lib in ($orgs)
- order by cast(upper(label) as bytea),4,2
+ order by oils_text_as_bytea(upper(label)),4,2
limit $bottomsize;
SQL
},
{ flesh => 1,
flesh_fields => { acn => [qw/record owning_lib/] },
- order_by => { acn => "cast(label_sortkey as bytea) desc, upper(label) desc, id desc, owning_lib desc" },
+ order_by => { acn => "oils_text_as_bytea(label_sortkey) desc, upper(label) desc, id desc, owning_lib desc" },
limit => $before_limit,
offset => abs($page) * $page_size - $before_offset,
}
},
{ flesh => 1,
flesh_fields => { acn => [qw/record owning_lib/] },
- order_by => { acn => "cast(label_sortkey as bytea), upper(label), id, owning_lib" },
+ order_by => { acn => "oils_text_as_bytea(label_sortkey), upper(label), id, owning_lib" },
limit => $after_limit,
offset => abs($page) * $page_size - $after_offset,
}
},
{ flesh => 1,
flesh_fields => { acn => [qw/record owning_lib/] },
- order_by => { acn => "cast(label_sortkey as bytea) desc, upper(label) desc, id desc, owning_lib desc" },
+ order_by => { acn => "oils_text_as_bytea(label_sortkey) desc, upper(label) desc, id desc, owning_lib desc" },
limit => $limit,
offset => $offset,
}
},
{ flesh => 1,
flesh_fields => { acn => [qw/record owning_lib/] },
- order_by => { acn => "cast(label_sortkey as bytea), upper(label), id, owning_lib" },
+ order_by => { acn => "oils_text_as_bytea(label_sortkey), upper(label), id, owning_lib" },
limit => $limit,
offset => $offset,
}
return;
$func$ LANGUAGE PLPERLU;
+CREATE OR REPLACE FUNCTION oils_text_as_bytea (TEXT) RETURNS BYTEA AS $_$
+ SELECT CAST(REGEXP_REPLACE($1, $$\\$$, $$\\\\$$, 'g') AS BYTEA);
+$_$ LANGUAGE SQL IMMUTABLE;
+
COMMIT;
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0438'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0439'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
CREATE INDEX asset_call_number_creator_idx ON asset.call_number (creator);
CREATE INDEX asset_call_number_editor_idx ON asset.call_number (editor);
CREATE INDEX asset_call_number_dewey_idx ON asset.call_number (public.call_number_dewey(label));
-CREATE INDEX asset_call_number_upper_label_id_owning_lib_idx ON asset.call_number (cast(upper(label) as bytea),id,owning_lib);
-CREATE INDEX asset_call_number_label_sortkey ON asset.call_number(cast(label_sortkey as bytea));
+CREATE INDEX asset_call_number_upper_label_id_owning_lib_idx ON asset.call_number (oils_text_as_bytea(upper(label)),id,owning_lib);
+CREATE INDEX asset_call_number_label_sortkey ON asset.call_number(oils_text_as_bytea(label_sortkey));
CREATE UNIQUE INDEX asset_call_number_label_once_per_lib ON asset.call_number (record, owning_lib, label) WHERE deleted = FALSE OR deleted IS FALSE;
CREATE RULE protect_cn_delete AS ON DELETE TO asset.call_number DO INSTEAD UPDATE asset.call_number SET deleted = TRUE WHERE OLD.id = asset.call_number.id;
CREATE TRIGGER asset_label_sortkey_trigger
ADD COLUMN label_sortkey TEXT;
CREATE INDEX asset_call_number_label_sortkey
- ON asset.call_number(cast(label_sortkey as bytea));
+ ON asset.call_number(oils_text_as_bytea(label_sortkey));
ALTER TABLE auditor.asset_call_number_history
ADD COLUMN label_class BIGINT;
--- /dev/null
+
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0439'); -- miker
+
+CREATE OR REPLACE FUNCTION oils_text_as_bytea (TEXT) RETURNS BYTEA AS $_$
+ SELECT CAST(REGEXP_REPLACE($1, $$\\$$, $$\\\\$$, 'g') AS BYTEA);
+$_$ LANGUAGE SQL IMMUTABLE;
+
+
+DROP INDEX asset.asset_call_number_upper_label_id_owning_lib_idx;
+CREATE INDEX asset_call_number_upper_label_id_owning_lib_idx ON asset.call_number (oils_text_as_bytea(label),id,owning_lib);
+
+DROP INDEX asset.asset_call_number_label_sortkey;
+CREATE INDEX asset_call_number_label_sortkey ON asset.call_number(oils_text_as_bytea(label_sortkey));
+
+COMMIT;