-- -- PostgreSQL database dump -- SET statement_timeout = 0; SET client_encoding = 'UTF8'; SET standard_conforming_strings = off; SET check_function_bodies = false; SET client_min_messages = warning; SET escape_string_warning = off; -- -- Name: functions; Type: SCHEMA; Schema: -; Owner: - -- CREATE SCHEMA functions; SET search_path = functions, pg_catalog; -- -- Name: datatype; Type: TYPE; Schema: functions; Owner: - -- CREATE TYPE datatype AS ENUM ( 'str', 'float' ); -- -- Name: _alt(); Type: FUNCTION; Schema: functions; Owner: - -- CREATE FUNCTION _alt() RETURNS trigger LANGUAGE plpgsql IMMUTABLE AS $$ BEGIN new.result := coalesce(new."0", new."1", new."2", new."3", new."4", new."5", new."6", new."7", new."8", new."9"); RETURN new; END; $$; -- -- Name: _label(); Type: FUNCTION; Schema: functions; Owner: - -- CREATE FUNCTION _label() RETURNS trigger LANGUAGE plpgsql IMMUTABLE AS $$ BEGIN new.result := (SELECT new.label||': '||new.value); RETURN new; END; $$; -- -- Name: _merge(); Type: FUNCTION; Schema: functions; Owner: - -- CREATE FUNCTION _merge() RETURNS trigger LANGUAGE plpgsql IMMUTABLE AS $$ BEGIN new.result := ( SELECT functions.join_strs('; ', value) FROM ( SELECT * FROM ( SELECT DISTINCT ON (value) * FROM (VALUES (0, new."0") , (1, new."1") , (2, new."2") , (3, new."3") , (4, new."4") , (5, new."5") , (6, new."6") , (7, new."7") , (8, new."8") , (9, new."9") ) AS v (sort_order, value) ) AS v ORDER BY sort_order ) AS v ); RETURN new; END; $$; -- -- Name: _nullIf(); Type: FUNCTION; Schema: functions; Owner: - -- CREATE FUNCTION "_nullIf"() RETURNS trigger LANGUAGE plpgsql IMMUTABLE AS $$ BEGIN IF new.result = 'str' THEN -- no cast needed new.result := (SELECT nullif(new.value, new."null")); -- Invalid value -> warning, but invalid null value -> error ELSIF new.result = 'float' THEN new.result := (SELECT nullif(functions."double precision"(new.value), new."null"::double precision)); END IF; RETURN new; END; $$; -- -- Name: boolean(text); Type: FUNCTION; Schema: functions; Owner: - -- CREATE FUNCTION "boolean"(value text) RETURNS boolean LANGUAGE plpgsql IMMUTABLE STRICT AS $$ BEGIN BEGIN RETURN value::boolean; EXCEPTION WHEN data_exception THEN RAISE WARNING '%', SQLERRM; RETURN NULL; END; RETURN new; END; $$; -- -- Name: double precision(text); Type: FUNCTION; Schema: functions; Owner: - -- CREATE FUNCTION "double precision"(value text) RETURNS double precision LANGUAGE plpgsql IMMUTABLE STRICT AS $$ BEGIN BEGIN RETURN value::double precision; EXCEPTION WHEN data_exception THEN RAISE WARNING '%', SQLERRM; RETURN NULL; END; RETURN new; END; $$; -- -- Name: ensure_not_null(text); Type: FUNCTION; Schema: functions; Owner: - -- CREATE FUNCTION ensure_not_null(value text) RETURNS text LANGUAGE sql IMMUTABLE AS $_$ SELECT COALESCE($1, E'\\N'); $_$; -- -- Name: join_strs_(text, text, text); Type: FUNCTION; Schema: functions; Owner: - -- CREATE FUNCTION join_strs_(state text, delim text, value text) RETURNS text LANGUAGE sql IMMUTABLE AS $_$ SELECT $1 || (CASE WHEN $1 = '' OR $3 IS NULL OR $3 = '' THEN '' ELSE $2 END) || coalesce($3, ''); $_$; -- -- Name: timestamp with time zone(text); Type: FUNCTION; Schema: functions; Owner: - -- CREATE FUNCTION "timestamp with time zone"(value text) RETURNS timestamp with time zone LANGUAGE plpgsql IMMUTABLE STRICT AS $$ BEGIN BEGIN RETURN value::timestamp with time zone; EXCEPTION WHEN data_exception THEN RAISE WARNING '%', SQLERRM; RETURN NULL; END; RETURN new; END; $$; -- -- Name: join_strs(text, text); Type: AGGREGATE; Schema: functions; Owner: - -- CREATE AGGREGATE join_strs(text, text) ( SFUNC = join_strs_, STYPE = text, INITCOND = '' ); SET default_tablespace = ''; SET default_with_oids = false; -- -- Name: !disabled!_nullIf; Type: TABLE; Schema: functions; Owner: -; Tablespace: -- CREATE TABLE "!disabled!_nullIf" ( result text, not_null_col boolean DEFAULT true NOT NULL, "null" text, type datatype DEFAULT 'str'::datatype NOT NULL, value text ); -- -- Name: _alt; Type: TABLE; Schema: functions; Owner: -; Tablespace: -- CREATE TABLE _alt ( result text, not_null_col boolean DEFAULT true NOT NULL, "0" text, "1" text, "2" text, "3" text, "4" text, "5" text, "6" text, "7" text, "8" text, "9" text ); -- -- Name: _label; Type: TABLE; Schema: functions; Owner: -; Tablespace: -- CREATE TABLE _label ( result text, not_null_col boolean DEFAULT true NOT NULL, label text, value text ); -- -- Name: _merge; Type: TABLE; Schema: functions; Owner: -; Tablespace: -- CREATE TABLE _merge ( result text, not_null_col boolean DEFAULT true NOT NULL, "0" text, "1" text, "2" text, "3" text, "4" text, "5" text, "6" text, "7" text, "8" text, "9" text ); -- -- Name: _alt_0; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _alt_0 ON _alt USING btree ("0"); -- -- Name: _alt_1; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _alt_1 ON _alt USING btree ("1"); -- -- Name: _alt_2; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _alt_2 ON _alt USING btree ("2"); -- -- Name: _alt_3; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _alt_3 ON _alt USING btree ("3"); -- -- Name: _alt_4; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _alt_4 ON _alt USING btree ("4"); -- -- Name: _alt_5; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _alt_5 ON _alt USING btree ("5"); -- -- Name: _alt_6; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _alt_6 ON _alt USING btree ("6"); -- -- Name: _alt_7; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _alt_7 ON _alt USING btree ("7"); -- -- Name: _alt_8; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _alt_8 ON _alt USING btree ("8"); -- -- Name: _alt_9; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _alt_9 ON _alt USING btree ("9"); -- -- Name: _alt_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE UNIQUE INDEX _alt_unique ON _alt USING btree (ensure_not_null("0"), ensure_not_null("1"), ensure_not_null("2"), ensure_not_null("3"), ensure_not_null("4"), ensure_not_null("5"), ensure_not_null("6"), ensure_not_null("7"), ensure_not_null("8"), ensure_not_null("9")); -- -- Name: _label_label; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _label_label ON _label USING btree (label); -- -- Name: _label_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE UNIQUE INDEX _label_unique ON _label USING btree (ensure_not_null(label), ensure_not_null(value)); -- -- Name: _label_value; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _label_value ON _label USING btree (value); -- -- Name: _merge_0; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _merge_0 ON _merge USING btree ("0"); -- -- Name: _merge_1; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _merge_1 ON _merge USING btree ("1"); -- -- Name: _merge_2; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _merge_2 ON _merge USING btree ("2"); -- -- Name: _merge_3; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _merge_3 ON _merge USING btree ("3"); -- -- Name: _merge_4; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _merge_4 ON _merge USING btree ("4"); -- -- Name: _merge_5; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _merge_5 ON _merge USING btree ("5"); -- -- Name: _merge_6; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _merge_6 ON _merge USING btree ("6"); -- -- Name: _merge_7; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _merge_7 ON _merge USING btree ("7"); -- -- Name: _merge_8; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _merge_8 ON _merge USING btree ("8"); -- -- Name: _merge_9; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX _merge_9 ON _merge USING btree ("9"); -- -- Name: _merge_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE UNIQUE INDEX _merge_unique ON _merge USING btree (ensure_not_null("0"), ensure_not_null("1"), ensure_not_null("2"), ensure_not_null("3"), ensure_not_null("4"), ensure_not_null("5"), ensure_not_null("6"), ensure_not_null("7"), ensure_not_null("8"), ensure_not_null("9")); -- -- Name: _nullIf_null; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX "_nullIf_null" ON "!disabled!_nullIf" USING btree ("null"); -- -- Name: _nullIf_type; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX "_nullIf_type" ON "!disabled!_nullIf" USING btree (type); -- -- Name: _nullIf_unique; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE UNIQUE INDEX "_nullIf_unique" ON "!disabled!_nullIf" USING btree (ensure_not_null("null"), type, ensure_not_null(value)); -- -- Name: _nullIf_value; Type: INDEX; Schema: functions; Owner: -; Tablespace: -- CREATE INDEX "_nullIf_value" ON "!disabled!_nullIf" USING btree (value); -- -- Name: _alt; Type: TRIGGER; Schema: functions; Owner: - -- CREATE TRIGGER _alt BEFORE INSERT OR UPDATE ON _alt FOR EACH ROW EXECUTE PROCEDURE _alt(); -- -- Name: _label; Type: TRIGGER; Schema: functions; Owner: - -- CREATE TRIGGER _label BEFORE INSERT OR UPDATE ON _label FOR EACH ROW EXECUTE PROCEDURE _label(); -- -- Name: _merge; Type: TRIGGER; Schema: functions; Owner: - -- CREATE TRIGGER _merge BEFORE INSERT OR UPDATE ON _merge FOR EACH ROW EXECUTE PROCEDURE _merge(); -- -- Name: _nullIf; Type: TRIGGER; Schema: functions; Owner: - -- CREATE TRIGGER "_nullIf" BEFORE INSERT OR UPDATE ON "!disabled!_nullIf" FOR EACH ROW EXECUTE PROCEDURE "_nullIf"(); -- -- PostgreSQL database dump complete --