From: Nicolas Boisselier Date: Sat, 26 May 2018 01:59:48 +0000 (+0100) Subject: lib/postgres/url.sql X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=75e7a7044b389f86b556efd3ef7bde40512a3e23;p=nb.git lib/postgres/url.sql --- diff --git a/lib/postgres/function/CONCAT.sql b/lib/postgres/function/CONCAT.sql new file mode 100644 index 00000000..1e139777 --- /dev/null +++ b/lib/postgres/function/CONCAT.sql @@ -0,0 +1,33 @@ +-- NB 21.06.16 CREATE AGGREGATE array_agg (anyelement) +-- NB 21.06.16 ( +-- NB 21.06.16 sfunc = array_append, +-- NB 21.06.16 stype = anyarray, +-- NB 21.06.16 initcond = '{}' +-- NB 21.06.16 ); + +DROP AGGREGATE IF EXISTS CONCAT(text); +/* +CREATE AGGREGATE CONCAT( + basetype = text, + sfunc = textcat, + stype = text, + initcond = '' + +); +*/ + +/* +DROP FUNCTION IF EXISTS CONCAT( VARIADIC ANYARRAY ); +CREATE FUNCTION CONCAT( VARIADIC ANYARRAY ) +RETURNS TEXT + LANGUAGE SQL + IMMUTABLE + AS $$ + SELECT array_to_string($1,''); +$$; +*/ + + + + + diff --git a/lib/postgres/functions.sql b/lib/postgres/functions.sql deleted file mode 100644 index 1e139777..00000000 --- a/lib/postgres/functions.sql +++ /dev/null @@ -1,33 +0,0 @@ --- NB 21.06.16 CREATE AGGREGATE array_agg (anyelement) --- NB 21.06.16 ( --- NB 21.06.16 sfunc = array_append, --- NB 21.06.16 stype = anyarray, --- NB 21.06.16 initcond = '{}' --- NB 21.06.16 ); - -DROP AGGREGATE IF EXISTS CONCAT(text); -/* -CREATE AGGREGATE CONCAT( - basetype = text, - sfunc = textcat, - stype = text, - initcond = '' - -); -*/ - -/* -DROP FUNCTION IF EXISTS CONCAT( VARIADIC ANYARRAY ); -CREATE FUNCTION CONCAT( VARIADIC ANYARRAY ) -RETURNS TEXT - LANGUAGE SQL - IMMUTABLE - AS $$ - SELECT array_to_string($1,''); -$$; -*/ - - - - - diff --git a/lib/postgres/url.sql b/lib/postgres/url.sql new file mode 100644 index 00000000..c9735241 --- /dev/null +++ b/lib/postgres/url.sql @@ -0,0 +1,28 @@ +DROP TABLE IF EXISTS content; +CREATE TABLE IF NOT EXISTS content ( + id SERIAL PRIMARY KEY, + type VARCHAR(250) NOT NULL, + title VARCHAR(250) NOT NULL, + created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + content TEXT NOT NULL +); +CREATE INDEX IF NOT EXISTS content_created ON content USING btree (created); +CREATE INDEX IF NOT EXISTS content_type ON content USING btree (type); +CREATE INDEX IF NOT EXISTS content_title ON content USING btree (title); + +DROP FUNCTION IF EXISTS content_before_insert(); +/* +*/ +CREATE FUNCTION content_before_insert() RETURNS trigger as 'BEGIN + NEW.updated = now(); + RETURN NEW; +END' LANGUAGE 'plpgsql'; + +DROP TRIGGER IF EXISTS content_before_insert ON content; +/* +*/ +CREATE TRIGGER content_before_insert BEFORE INSERT OR UPDATE ON content +FOR EACH ROW +EXECUTE PROCEDURE content_before_insert() +;