From 0a5f6f839de5ee8219eb1ddf9766f7374fbed419 Mon Sep 17 00:00:00 2001 From: scottmk Date: Fri, 4 Jun 2010 19:00:55 +0000 Subject: [PATCH] Add two little utility functions to convert from intervals to seconds. M Open-ILS/src/sql/Pg/999.functions.global.sql M Open-ILS/src/sql/Pg/002.schema.config.sql A Open-ILS/src/sql/Pg/upgrade/0293.function.interval-to-seconds.sql git-svn-id: svn://svn.open-ils.org/ILS/trunk@16594 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/999.functions.global.sql | 15 +++++++++++++++ .../Pg/upgrade/0293.function.interval-to-seconds.sql | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/0293.function.interval-to-seconds.sql diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 15b9afbdcf..68adf49850 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -65,7 +65,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0292'); -- dbs +INSERT INTO config.upgrade_log (version) VALUES ('0293'); -- Scott McKellar CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 85d3c9bbc4..57c6a7be54 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -1116,3 +1116,18 @@ CREATE TRIGGER fingerprint_tgr BEFORE INSERT OR UPDATE ON biblio.record_entry FO CREATE TRIGGER aaa_indexing_ingest_or_delete AFTER INSERT OR UPDATE ON biblio.record_entry FOR EACH ROW EXECUTE PROCEDURE biblio.indexing_ingest_or_delete (); CREATE TRIGGER bbb_simple_rec_trigger AFTER INSERT OR UPDATE ON biblio.record_entry FOR EACH ROW EXECUTE PROCEDURE reporter.simple_rec_trigger (); +-- Utility routines, callable via cstore + +CREATE OR REPLACE FUNCTION config.interval_to_seconds( interval_val INTERVAL ) +RETURNS INTEGER AS $$ +BEGIN + RETURN EXTRACT( EPOCH FROM interval_val ); +END; +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION config.interval_to_seconds( interval_string TEXT ) +RETURNS INTEGER AS $$ +BEGIN + RETURN config.interval_to_seconds( interval_string::INTERVAL ); +END; +$$ LANGUAGE plpgsql; diff --git a/Open-ILS/src/sql/Pg/upgrade/0293.function.interval-to-seconds.sql b/Open-ILS/src/sql/Pg/upgrade/0293.function.interval-to-seconds.sql new file mode 100644 index 0000000000..22f6f5dfe9 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/0293.function.interval-to-seconds.sql @@ -0,0 +1,19 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('0293'); -- Scott McKellar + +CREATE OR REPLACE FUNCTION config.interval_to_seconds( interval_val INTERVAL ) +RETURNS INTEGER AS $$ +BEGIN + RETURN EXTRACT( EPOCH FROM interval_val ); +END; +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION config.interval_to_seconds( interval_string TEXT ) +RETURNS INTEGER AS $$ +BEGIN + RETURN config.interval_to_seconds( interval_string::INTERVAL ); +END; +$$ LANGUAGE plpgsql; + +COMMIT; -- 2.11.0