├── .gitignore ├── LICENSE.md ├── META.json ├── PGXNREADME.md ├── README.md ├── build.cfg.example ├── create_html_doc.sh ├── create_pgxn_doc.sh ├── create_sql.sh ├── help.html ├── makefile ├── pgsql_tweaks.control ├── sql ├── aggregate_function_gap_fill.sql ├── function_array_avg.sql ├── function_array_max.sql ├── function_array_min.sql ├── function_array_sum.sql ├── function_array_trim.sql ├── function_date_de.sql ├── function_datetime_de.sql ├── function_get_markdown_doku_by_schema.sql ├── function_hex2bigint.sql ├── function_is_bigint.sql ├── function_is_bigint_array.sql ├── function_is_boolean.sql ├── function_is_date.sql ├── function_is_double_precision.sql ├── function_is_empty.sql ├── function_is_encoding.sql ├── function_is_hex.sql ├── function_is_integer.sql ├── function_is_integer_array.sql ├── function_is_json.sql ├── function_is_jsonb.sql ├── function_is_latin1.sql ├── function_is_numeric.sql ├── function_is_real.sql ├── function_is_smallint.sql ├── function_is_smallint_array.sql ├── function_is_text_array.sql ├── function_is_time.sql ├── function_is_timestamp.sql ├── function_is_uuid.sql ├── function_pg_schema_size.sql ├── function_replace_encoding.sql ├── function_replace_latin1.sql ├── function_return_not_part_of_encoding.sql ├── function_return_not_part_of_latin1.sql ├── function_sha256.sql ├── function_to_unix_timestamp.sql ├── gab_fill.sql ├── out │ ├── uninstall │ │ ├── pgsql_tweaks_uninstall--0.1.0.sql │ │ ├── pgsql_tweaks_uninstall--0.1.1.sql │ │ ├── pgsql_tweaks_uninstall--0.10.0.sql │ │ ├── pgsql_tweaks_uninstall--0.10.1.sql │ │ ├── pgsql_tweaks_uninstall--0.10.2.sql │ │ ├── pgsql_tweaks_uninstall--0.10.3.sql │ │ ├── pgsql_tweaks_uninstall--0.10.4.sql │ │ ├── pgsql_tweaks_uninstall--0.10.5.sql │ │ ├── pgsql_tweaks_uninstall--0.10.6.sql │ │ ├── pgsql_tweaks_uninstall--0.10.7.sql │ │ ├── pgsql_tweaks_uninstall--0.11.0.sql │ │ ├── pgsql_tweaks_uninstall--0.11.1.sql │ │ ├── pgsql_tweaks_uninstall--0.2.0.sql │ │ ├── pgsql_tweaks_uninstall--0.2.1.sql │ │ ├── pgsql_tweaks_uninstall--0.2.2.sql │ │ ├── pgsql_tweaks_uninstall--0.2.3.sql │ │ ├── pgsql_tweaks_uninstall--0.2.4.sql │ │ ├── pgsql_tweaks_uninstall--0.2.5.sql │ │ ├── pgsql_tweaks_uninstall--0.3.0.sql │ │ ├── pgsql_tweaks_uninstall--0.3.1.sql │ │ ├── pgsql_tweaks_uninstall--0.4.0.sql │ │ ├── pgsql_tweaks_uninstall--0.4.1.sql │ │ ├── pgsql_tweaks_uninstall--0.4.2.sql │ │ ├── pgsql_tweaks_uninstall--0.5.0.sql │ │ ├── pgsql_tweaks_uninstall--0.6.0.sql │ │ ├── pgsql_tweaks_uninstall--0.7.0.sql │ │ ├── pgsql_tweaks_uninstall--0.7.1.sql │ │ ├── pgsql_tweaks_uninstall--0.8.0.sql │ │ ├── pgsql_tweaks_uninstall--0.9.0.sql │ │ └── pgsql_tweaks_uninstall--0.9.1.sql │ └── versions │ │ ├── pgsql_tweaks--0.1.0.sql │ │ ├── pgsql_tweaks--0.1.1.sql │ │ ├── pgsql_tweaks--0.10.0.sql │ │ ├── pgsql_tweaks--0.10.1.sql │ │ ├── pgsql_tweaks--0.10.2.sql │ │ ├── pgsql_tweaks--0.10.3.sql │ │ ├── pgsql_tweaks--0.10.4.sql │ │ ├── pgsql_tweaks--0.10.5.sql │ │ ├── pgsql_tweaks--0.10.6.sql │ │ ├── pgsql_tweaks--0.10.7.sql │ │ ├── pgsql_tweaks--0.11.0.sql │ │ ├── pgsql_tweaks--0.11.1.sql │ │ ├── pgsql_tweaks--0.2.0.sql │ │ ├── pgsql_tweaks--0.2.1.sql │ │ ├── pgsql_tweaks--0.2.2.sql │ │ ├── pgsql_tweaks--0.2.3.sql │ │ ├── pgsql_tweaks--0.2.4.sql │ │ ├── pgsql_tweaks--0.2.5.sql │ │ ├── pgsql_tweaks--0.3.0.sql │ │ ├── pgsql_tweaks--0.3.1.sql │ │ ├── pgsql_tweaks--0.4.0.sql │ │ ├── pgsql_tweaks--0.4.1.sql │ │ ├── pgsql_tweaks--0.4.2.sql │ │ ├── pgsql_tweaks--0.5.0.sql │ │ ├── pgsql_tweaks--0.6.0.sql │ │ ├── pgsql_tweaks--0.7.0.sql │ │ ├── pgsql_tweaks--0.7.1.sql │ │ ├── pgsql_tweaks--0.8.0.sql │ │ ├── pgsql_tweaks--0.9.0.sql │ │ └── pgsql_tweaks--0.9.1.sql ├── view_pg_active_locks.sql ├── view_pg_bloat_info.sql ├── view_pg_db_views.sql ├── view_pg_foreign_keys.sql ├── view_pg_functions.sql ├── view_pg_object_ownership.sql ├── view_pg_partitioned_tables_infos.sql ├── view_pg_table_matview_infos.sql └── view_pg_unused_indexes.sql └── test └── sql ├── aggregate_function_gap_fill.sql ├── examples.sql ├── function_array_avg.sql ├── function_array_max.sql ├── function_array_min.sql ├── function_array_sum.sql ├── function_array_trim.sql ├── function_date_de.sql ├── function_datetime_de.sql ├── function_hex2bigint.sql ├── function_is_bigint.sql ├── function_is_bigint_array.sql ├── function_is_boolean.sql ├── function_is_date.sql ├── function_is_double_precision.sql ├── function_is_empty.sql ├── function_is_encoding.sql ├── function_is_hex.sql ├── function_is_integer.sql ├── function_is_integer_array.sql ├── function_is_json.sql ├── function_is_jsonb.sql ├── function_is_latin1.sql ├── function_is_numeric.sql ├── function_is_real.sql ├── function_is_smallint.sql ├── function_is_smallint_array.sql ├── function_is_text_array.sql ├── function_is_time.sql ├── function_is_timestamp.sql ├── function_is_uuid.sql ├── function_pg_schema_size.sql ├── function_replace_encoding.sql ├── function_replace_latin1.sql ├── function_return_not_part_of_encoding.sql ├── function_return_not_part_of_latin1.sql ├── function_sha256.sql ├── function_to_unix_timestamp.sql ├── get_markdown_doku_by_schema.sql ├── out ├── pgsql_tweaks_test--0.1.0 ├── pgsql_tweaks_test--0.1.0.sql ├── pgsql_tweaks_test--0.1.1 ├── pgsql_tweaks_test--0.1.1.sql ├── pgsql_tweaks_test--0.10.0.out ├── pgsql_tweaks_test--0.10.0.sql ├── pgsql_tweaks_test--0.10.1.out ├── pgsql_tweaks_test--0.10.1.sql ├── pgsql_tweaks_test--0.10.2.out ├── pgsql_tweaks_test--0.10.2.sql ├── pgsql_tweaks_test--0.10.3.out ├── pgsql_tweaks_test--0.10.3.sql ├── pgsql_tweaks_test--0.10.4.out ├── pgsql_tweaks_test--0.10.4.sql ├── pgsql_tweaks_test--0.10.5.out ├── pgsql_tweaks_test--0.10.5.sql ├── pgsql_tweaks_test--0.10.6.out ├── pgsql_tweaks_test--0.10.6.sql ├── pgsql_tweaks_test--0.10.7.out ├── pgsql_tweaks_test--0.10.7.sql ├── pgsql_tweaks_test--0.11.0.out ├── pgsql_tweaks_test--0.11.0.sql ├── pgsql_tweaks_test--0.11.1.out ├── pgsql_tweaks_test--0.11.1.sql ├── pgsql_tweaks_test--0.2.0.out ├── pgsql_tweaks_test--0.2.0.sql ├── pgsql_tweaks_test--0.2.1.out ├── pgsql_tweaks_test--0.2.1.sql ├── pgsql_tweaks_test--0.2.2.out ├── pgsql_tweaks_test--0.2.2.sql ├── pgsql_tweaks_test--0.2.3.out ├── pgsql_tweaks_test--0.2.3.sql ├── pgsql_tweaks_test--0.2.4.out ├── pgsql_tweaks_test--0.2.4.sql ├── pgsql_tweaks_test--0.2.5.out ├── pgsql_tweaks_test--0.2.5.sql ├── pgsql_tweaks_test--0.3.0.out ├── pgsql_tweaks_test--0.3.0.sql ├── pgsql_tweaks_test--0.3.1.out ├── pgsql_tweaks_test--0.3.1.sql ├── pgsql_tweaks_test--0.4.0.out ├── pgsql_tweaks_test--0.4.0.sql ├── pgsql_tweaks_test--0.4.1.out ├── pgsql_tweaks_test--0.4.1.sql ├── pgsql_tweaks_test--0.4.2.out ├── pgsql_tweaks_test--0.4.2.sql ├── pgsql_tweaks_test--0.5.0.out ├── pgsql_tweaks_test--0.5.0.sql ├── pgsql_tweaks_test--0.6.0.out ├── pgsql_tweaks_test--0.6.0.sql ├── pgsql_tweaks_test--0.7.0.out ├── pgsql_tweaks_test--0.7.0.sql ├── pgsql_tweaks_test--0.7.1.out ├── pgsql_tweaks_test--0.7.1.sql ├── pgsql_tweaks_test--0.8.0.out ├── pgsql_tweaks_test--0.8.0.sql ├── pgsql_tweaks_test--0.9.0.out ├── pgsql_tweaks_test--0.9.0.sql ├── pgsql_tweaks_test--0.9.1.out └── pgsql_tweaks_test--0.9.1.sql ├── view_pg_active_locks.sql ├── view_pg_bloat_info.sql ├── view_pg_db_views.sql ├── view_pg_foreign_keys.sql ├── view_pg_functions.sql ├── view_pg_object_ownership.sql ├── view_pg_partitioned_tables_infos.sql ├── view_pg_table_matview_infos.sql └── view_pg_unused_indexes.sql /.gitignore: -------------------------------------------------------------------------------- 1 | language.json 2 | build.cfg 3 | archive 4 | .project 5 | .dbeaver* 6 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | PostgreSQL Licence 2 | 3 | Copyright (c) 2018 Stefanie Janine Stölting 4 | 5 | Permission to use, copy, modify, and distribute this software and its 6 | documentation for any purpose, without fee, and without a written agreement is 7 | hereby granted, provided that the above copyright notice and this paragraph 8 | and the following two paragraphs appear in all copies. 9 | 10 | IN NO EVENT SHALL Stefanie Janine Stölting BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, 11 | SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING 12 | OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF Stefanie Janine Stölting 13 | HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14 | 15 | Stefanie Janine Stölting SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 16 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 17 | PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, 18 | AND Stefanie Janine Stölting HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 19 | ENHANCEMENTS, OR MODIFICATIONS. 20 | -------------------------------------------------------------------------------- /META.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pgsql_tweaks", 3 | "abstract": "Contains PostgreSQL functions which I regularly needed.", 4 | "description": "The package includes several functions and views to help daily work.", 5 | "version": "0.11.1", 6 | "maintainer": [ 7 | "Stefanie Janine Stölting " 8 | ], 9 | "license": { 10 | "PostgreSQL": "https://www.postgresql.org/about/licence" 11 | }, 12 | "prereqs": { 13 | "runtime": { 14 | "requires": { 15 | "plpgsql": 0, 16 | "PostgreSQL": "13.0.0" 17 | }, 18 | "recommends": { 19 | "PostgreSQL": "17.0.0" 20 | } 21 | } 22 | }, 23 | "provides": { 24 | "pgsql_tweaks": { 25 | "abstract": "Contains PostgreSQL functions and views which I regularly needed and might help others, too.", 26 | "file": "sql/out/versions/pgsql_tweaks--0.10.7.sql", 27 | "docfile": "PGXNREADME.md", 28 | "version": "0.17.0" 29 | } 30 | }, 31 | "resources": { 32 | "bugtracker": { 33 | "web": "https://gitlab.com/sjstoelting/pgsql-tweaks/-/issues" 34 | }, 35 | "repository": { 36 | "url": "https://gitlab.com/sjstoelting/pgsql-tweaks.git", 37 | "web": "https://gitlab.com/sjstoelting/pgsql-tweaks", 38 | "type": "git" 39 | } 40 | }, 41 | "release_status": "stable", 42 | "generated_by": "Stefanie Janine Stölting", 43 | "meta-spec": { 44 | "version": "1.0.0", 45 | "url": "http://pgxn.org/meta/spec.txt" 46 | }, 47 | "tags": [ 48 | "is_date", 49 | "is_time", 50 | "is_timestamp", 51 | "is_integer", 52 | "is_numeric", 53 | "is_boolean", 54 | "is_json", 55 | "is_encoding", 56 | "encoding", 57 | "array aggregates", 58 | "datatype checks", 59 | "extended system views" 60 | ] 61 | } 62 | -------------------------------------------------------------------------------- /build.cfg.example: -------------------------------------------------------------------------------- 1 | DBNAME=pgsql_tweaks_test 2 | DBPORT=5432 3 | DBHOST=localhost 4 | -------------------------------------------------------------------------------- /create_html_doc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Creates a documentation in HTML 3 | # Input file 4 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 5 | FILENAME="$DIR/README.md" 6 | 7 | FILECONTENT="$(cat $FILENAME)" 8 | 9 | # Outpup file 10 | OUTPUTFILENAME="$DIR/help.html" 11 | 12 | # Empty the output file 13 | truncate -s 0 $OUTPUTFILENAME 14 | 15 | # Write HTML from github API to the output file 16 | curl https://api.github.com/markdown/raw -X "POST" -H "Content-Type: text/plain" -d "$FILECONTENT" >> $OUTPUTFILENAME 17 | 18 | # Replace the internal links to make them work 19 | sed -i -e 's/> "$EXPORTFILENAME" 31 | done < "$FILENAME" 32 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | #EXTENSION = pgsql_tweaks 2 | EXTENSION = $(shell grep -m 1 '"name":' META.json | \ 3 | sed -e 's/[[:space:]]*"name":[[:space:]]*"\([^"]*\)",/\1/') 4 | EXTVERSION = $(shell grep -m 1 '"version":' META.json | \ 5 | sed -e 's/[[:space:]]*"version":[[:space:]]*"\([^"]*\)",/\1/') 6 | 7 | NUMVERSION = $(shell echo $(EXTVERSION) | sed -e 's/\([[:digit:]]*[.][[:digit:]]*\).*/\1/') 8 | DATA = sql/out/versions/$(EXTENSION)--$(EXTVERSION).sql 9 | TESTS = test/sql/out/$(EXTENSION)_test--$(EXTVERSION).sql 10 | REGRESS = test/sql/out/$(EXTENSION)_test--$(EXTVERSION).out 11 | DOCS = README.md 12 | 13 | PG_CONFIG = pg_config 14 | 15 | PGXS := $(shell $(PG_CONFIG) --pgxs) 16 | include $(PGXS) 17 | -------------------------------------------------------------------------------- /pgsql_tweaks.control: -------------------------------------------------------------------------------- 1 | # pgsql_tweaks extension 2 | comment = 'Some functions and views for daily usage' 3 | default_version = '0.11.1' 4 | module_pathname = '$libdir/pgsql_tweaks' 5 | relocatable = true 6 | -------------------------------------------------------------------------------- /sql/aggregate_function_gap_fill.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Create a window function to calculate values for gaps. 3 | */ 4 | CREATE OR REPLACE FUNCTION gap_fill_internal(s anyelement, v anyelement) 5 | RETURNS anyelement AS 6 | $$ 7 | BEGIN 8 | RETURN COALESCE(v, s); 9 | END; 10 | $$ LANGUAGE PLPGSQL IMMUTABLE; 11 | COMMENT ON FUNCTION gap_fill_internal(s anyelement, v anyelement) IS 'The function is used to fill gaps in window functions'; 12 | 13 | 14 | -- The Window function needs an aggregate 15 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 16 | CREATE AGGREGATE gap_fill(anyelement) ( 17 | SFUNC=gap_fill_internal, 18 | STYPE = anyelement 19 | ) 20 | ; 21 | COMMENT ON AGGREGATE gap_fill(anyelement) IS 'Implements the aggregate function to fill gaps using the function GapFillInternal'; 22 | -------------------------------------------------------------------------------- /sql/function_array_avg.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns the average value of an array. 3 | * Implementation for BIGINT, INTEGER, SMALLINT 4 | */ 5 | 6 | -- BIGINT implementation 7 | CREATE OR REPLACE FUNCTION array_avg(a BIGINT[]) RETURNS NUMERIC AS $$ 8 | DECLARE 9 | res NUMERIC; 10 | BEGIN 11 | 12 | WITH unnested AS 13 | ( 14 | SELECT UNNEST(a) AS vals 15 | ) 16 | SELECT avg(vals) FROM unnested AS x INTO res; 17 | 18 | RETURN res; 19 | 20 | END; 21 | $$ 22 | STRICT 23 | LANGUAGE plpgsql IMMUTABLE 24 | ; 25 | COMMENT ON FUNCTION array_avg(a BIGINT[]) IS 'Returns the average value of a BIGINT array'; 26 | 27 | -- INTEGER implementation 28 | CREATE OR REPLACE FUNCTION array_avg(a INTEGER[]) RETURNS NUMERIC AS $$ 29 | DECLARE 30 | res NUMERIC; 31 | BEGIN 32 | 33 | WITH unnested AS 34 | ( 35 | SELECT UNNEST(a) AS vals 36 | ) 37 | SELECT avg(vals) FROM unnested AS x INTO res; 38 | 39 | RETURN res; 40 | 41 | END; 42 | $$ 43 | STRICT 44 | LANGUAGE plpgsql IMMUTABLE 45 | ; 46 | COMMENT ON FUNCTION array_avg(a INTEGER[]) IS 'Returns the average value of an INTEGER array'; 47 | 48 | -- SMALLINT implementation 49 | CREATE OR REPLACE FUNCTION array_avg(a SMALLINT[]) RETURNS NUMERIC AS $$ 50 | DECLARE 51 | res NUMERIC; 52 | BEGIN 53 | 54 | WITH unnested AS 55 | ( 56 | SELECT UNNEST(a) AS vals 57 | ) 58 | SELECT avg(vals) FROM unnested AS x INTO res; 59 | 60 | RETURN res; 61 | 62 | END; 63 | $$ 64 | STRICT 65 | LANGUAGE plpgsql IMMUTABLE 66 | ; 67 | COMMENT ON FUNCTION array_avg(a SMALLINT[]) IS 'Returns the average value of a SMALLINT array'; 68 | 69 | --REAL implementation 70 | CREATE OR REPLACE FUNCTION array_avg(a REAL[]) RETURNS NUMERIC AS $$ 71 | DECLARE 72 | res NUMERIC; 73 | BEGIN 74 | 75 | WITH unnested AS 76 | ( 77 | SELECT UNNEST(a) AS vals 78 | ) 79 | SELECT avg(vals) FROM unnested AS x INTO res; 80 | 81 | RETURN res; 82 | 83 | END; 84 | $$ 85 | STRICT 86 | LANGUAGE plpgsql IMMUTABLE 87 | ; 88 | COMMENT ON FUNCTION array_avg(a REAL[]) IS 'Returns the average value of a REAL array'; 89 | 90 | -- DOUBLE PRECISION implementation 91 | CREATE OR REPLACE FUNCTION array_avg(a DOUBLE PRECISION[]) RETURNS NUMERIC AS $$ 92 | DECLARE 93 | res NUMERIC; 94 | BEGIN 95 | 96 | WITH unnested AS 97 | ( 98 | SELECT UNNEST(a) AS vals 99 | ) 100 | SELECT avg(vals) FROM unnested AS x INTO res; 101 | 102 | RETURN res; 103 | 104 | END; 105 | $$ 106 | STRICT 107 | LANGUAGE plpgsql IMMUTABLE 108 | ; 109 | COMMENT ON FUNCTION array_avg(a DOUBLE PRECISION[]) IS 'Returns the average value of a DOUBLE PRECISION array'; 110 | 111 | -- NUMERIC implementation 112 | CREATE OR REPLACE FUNCTION array_avg(a NUMERIC[]) RETURNS NUMERIC AS $$ 113 | DECLARE 114 | res NUMERIC; 115 | BEGIN 116 | 117 | WITH unnested AS 118 | ( 119 | SELECT UNNEST(a) AS vals 120 | ) 121 | SELECT avg(vals) FROM unnested AS x INTO res; 122 | 123 | RETURN res; 124 | 125 | END; 126 | $$ 127 | STRICT 128 | LANGUAGE plpgsql IMMUTABLE 129 | ; 130 | COMMENT ON FUNCTION array_avg(a NUMERIC[]) IS 'Returns the average value of a NUMERIC array'; 131 | -------------------------------------------------------------------------------- /sql/function_array_max.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns the maximum value of an array. 3 | * Implementation for BIGINT, INTEGER, SMALLINT, TEXT 4 | */ 5 | 6 | -- BIGINT implementation 7 | CREATE OR REPLACE FUNCTION array_max(a BIGINT[]) RETURNS BIGINT AS $$ 8 | DECLARE 9 | res BIGINT; 10 | BEGIN 11 | 12 | WITH unnested AS 13 | ( 14 | SELECT UNNEST(a) AS vals 15 | ) 16 | SELECT max(vals) FROM unnested AS x INTO res; 17 | 18 | RETURN res; 19 | 20 | END; 21 | $$ 22 | STRICT 23 | LANGUAGE plpgsql IMMUTABLE 24 | ; 25 | COMMENT ON FUNCTION array_max(a BIGINT[]) IS 'Returns the maximum value of a BIGINT array'; 26 | 27 | -- INTEGER implementation 28 | CREATE OR REPLACE FUNCTION array_max(a INTEGER[]) RETURNS BIGINT AS $$ 29 | DECLARE 30 | res INTEGER; 31 | BEGIN 32 | 33 | WITH unnested AS 34 | ( 35 | SELECT UNNEST(a) AS vals 36 | ) 37 | SELECT max(vals) FROM unnested AS x INTO res; 38 | 39 | RETURN res; 40 | 41 | END; 42 | $$ 43 | STRICT 44 | LANGUAGE plpgsql IMMUTABLE 45 | ; 46 | COMMENT ON FUNCTION array_max(a INTEGER[]) IS 'Returns the maximum value of an INTEGER array'; 47 | 48 | -- SMALLINT implementation 49 | CREATE OR REPLACE FUNCTION array_max(a SMALLINT[]) RETURNS BIGINT AS $$ 50 | DECLARE 51 | res SMALLINT; 52 | BEGIN 53 | 54 | WITH unnested AS 55 | ( 56 | SELECT UNNEST(a) AS vals 57 | ) 58 | SELECT max(vals) FROM unnested AS x INTO res; 59 | 60 | RETURN res; 61 | 62 | END; 63 | $$ 64 | STRICT 65 | LANGUAGE plpgsql IMMUTABLE 66 | ; 67 | COMMENT ON FUNCTION array_max(a SMALLINT[]) IS 'Returns the maximum value of a SMALLINT array'; 68 | 69 | -- TEXT implementation 70 | CREATE OR REPLACE FUNCTION array_max(a TEXT[]) RETURNS TEXT AS $$ 71 | DECLARE 72 | res TEXT; 73 | BEGIN 74 | 75 | WITH unnested AS 76 | ( 77 | SELECT UNNEST(a) AS vals 78 | ) 79 | SELECT max(vals) FROM unnested AS x INTO res; 80 | 81 | RETURN res; 82 | 83 | END; 84 | $$ 85 | STRICT 86 | LANGUAGE plpgsql IMMUTABLE 87 | ; 88 | COMMENT ON FUNCTION array_max(a TEXT[]) IS 'Returns the maximum value of a TEXT array'; 89 | 90 | -- REAL implementation 91 | CREATE OR REPLACE FUNCTION array_max(a REAL[]) RETURNS NUMERIC AS $$ 92 | DECLARE 93 | res NUMERIC; 94 | BEGIN 95 | 96 | WITH unnested AS 97 | ( 98 | SELECT UNNEST(a) AS vals 99 | ) 100 | SELECT max(vals) FROM unnested AS x INTO res; 101 | 102 | RETURN res; 103 | 104 | END; 105 | $$ 106 | STRICT 107 | LANGUAGE plpgsql IMMUTABLE 108 | ; 109 | COMMENT ON FUNCTION array_max(a REAL[]) IS 'Returns the maximum value of a REAL array'; 110 | 111 | -- DOUBLE PRECISION implementation 112 | CREATE OR REPLACE FUNCTION array_max(a DOUBLE PRECISION[]) RETURNS NUMERIC AS $$ 113 | DECLARE 114 | res NUMERIC; 115 | BEGIN 116 | 117 | WITH unnested AS 118 | ( 119 | SELECT UNNEST(a) AS vals 120 | ) 121 | SELECT max(vals) FROM unnested AS x INTO res; 122 | 123 | RETURN res; 124 | 125 | END; 126 | $$ 127 | STRICT 128 | LANGUAGE plpgsql IMMUTABLE 129 | ; 130 | COMMENT ON FUNCTION array_max(a DOUBLE PRECISION[]) IS 'Returns the maximum value of a DOUBLE PRECISION array'; 131 | 132 | -- NUMERIC implementation 133 | CREATE OR REPLACE FUNCTION array_max(a NUMERIC[]) RETURNS NUMERIC AS $$ 134 | DECLARE 135 | res NUMERIC; 136 | BEGIN 137 | 138 | WITH unnested AS 139 | ( 140 | SELECT UNNEST(a) AS vals 141 | ) 142 | SELECT max(vals) FROM unnested AS x INTO res; 143 | 144 | RETURN res; 145 | 146 | END; 147 | $$ 148 | STRICT 149 | LANGUAGE plpgsql IMMUTABLE 150 | ; 151 | COMMENT ON FUNCTION array_max(a NUMERIC[]) IS 'Returns the maximum value of a NUMERIC array'; 152 | -------------------------------------------------------------------------------- /sql/function_array_min.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns the minumum value of an array. 3 | * Implementation for BIGINT, INTEGER, SMALLINT, TEXT 4 | */ 5 | 6 | -- BIGINT implementation 7 | CREATE OR REPLACE FUNCTION array_min(a BIGINT[]) RETURNS BIGINT AS $$ 8 | DECLARE 9 | res BIGINT; 10 | BEGIN 11 | 12 | WITH unnested AS 13 | ( 14 | SELECT UNNEST(a) AS vals 15 | ) 16 | SELECT min(vals) FROM unnested AS x INTO res; 17 | 18 | RETURN res; 19 | 20 | END; 21 | $$ 22 | STRICT 23 | LANGUAGE plpgsql IMMUTABLE 24 | ; 25 | COMMENT ON FUNCTION array_min(a BIGINT[]) IS 'Returns the minumum value of a BIGINT array'; 26 | 27 | -- INTEGER implementation 28 | CREATE OR REPLACE FUNCTION array_min(a INTEGER[]) RETURNS INTEGER AS $$ 29 | DECLARE 30 | res INTEGER; 31 | BEGIN 32 | 33 | WITH unnested AS 34 | ( 35 | SELECT UNNEST(a) AS vals 36 | ) 37 | SELECT min(vals) FROM unnested AS x INTO res; 38 | 39 | RETURN res; 40 | 41 | END; 42 | $$ 43 | STRICT 44 | LANGUAGE plpgsql IMMUTABLE 45 | ; 46 | COMMENT ON FUNCTION array_min(a INTEGER[]) IS 'Returns the minumum value of an INTEGER array'; 47 | 48 | -- SMALLINT implementation 49 | CREATE OR REPLACE FUNCTION array_min(a SMALLINT[]) RETURNS SMALLINT AS $$ 50 | DECLARE 51 | res SMALLINT; 52 | BEGIN 53 | 54 | WITH unnested AS 55 | ( 56 | SELECT UNNEST(a) AS vals 57 | ) 58 | SELECT min(vals) FROM unnested AS x INTO res; 59 | 60 | RETURN res; 61 | 62 | END; 63 | $$ 64 | STRICT 65 | LANGUAGE plpgsql IMMUTABLE 66 | ; 67 | COMMENT ON FUNCTION array_min(a SMALLINT[]) IS 'Returns the minumum value of a SMALLINT array'; 68 | 69 | -- TEXT implementation 70 | CREATE OR REPLACE FUNCTION array_min(a TEXT[]) RETURNS TEXT AS $$ 71 | DECLARE 72 | res TEXT; 73 | BEGIN 74 | 75 | WITH unnested AS 76 | ( 77 | SELECT UNNEST(a) AS vals 78 | ) 79 | SELECT min(vals) FROM unnested AS x INTO res; 80 | 81 | RETURN res; 82 | 83 | END; 84 | $$ 85 | STRICT 86 | LANGUAGE plpgsql IMMUTABLE 87 | ; 88 | COMMENT ON FUNCTION array_min(a TEXT[]) IS 'Returns the minumum value of a TEXT array'; 89 | 90 | -- REAL implementation 91 | CREATE OR REPLACE FUNCTION array_min(a REAL[]) RETURNS NUMERIC AS $$ 92 | DECLARE 93 | res NUMERIC; 94 | BEGIN 95 | 96 | WITH unnested AS 97 | ( 98 | SELECT UNNEST(a) AS vals 99 | ) 100 | SELECT min(vals) FROM unnested AS x INTO res; 101 | 102 | RETURN res; 103 | 104 | END; 105 | $$ 106 | STRICT 107 | LANGUAGE plpgsql IMMUTABLE 108 | ; 109 | COMMENT ON FUNCTION array_min(a REAL[]) IS 'Returns the minumum value of a REAL array'; 110 | 111 | -- DOUBLE PRECISION implementation 112 | CREATE OR REPLACE FUNCTION array_min(a DOUBLE PRECISION[]) RETURNS NUMERIC AS $$ 113 | DECLARE 114 | res NUMERIC; 115 | BEGIN 116 | 117 | WITH unnested AS 118 | ( 119 | SELECT UNNEST(a) AS vals 120 | ) 121 | SELECT min(vals) FROM unnested AS x INTO res; 122 | 123 | RETURN res; 124 | 125 | END; 126 | $$ 127 | STRICT 128 | LANGUAGE plpgsql IMMUTABLE 129 | ; 130 | COMMENT ON FUNCTION array_min(a DOUBLE PRECISION[]) IS 'Returns the minumum value of a DOUBLE PRECISION array'; 131 | 132 | -- NUMERIC implementation 133 | CREATE OR REPLACE FUNCTION array_min(a NUMERIC[]) RETURNS NUMERIC AS $$ 134 | DECLARE 135 | res REAL; 136 | BEGIN 137 | 138 | WITH unnested AS 139 | ( 140 | SELECT UNNEST(a) AS vals 141 | ) 142 | SELECT min(vals) FROM unnested AS x INTO res; 143 | 144 | RETURN res; 145 | 146 | END; 147 | $$ 148 | STRICT 149 | LANGUAGE plpgsql IMMUTABLE 150 | ; 151 | COMMENT ON FUNCTION array_min(a NUMERIC[]) IS 'Returns the minumum value of a NUMERIC array'; 152 | -------------------------------------------------------------------------------- /sql/function_array_sum.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns the sum of values of an array. 3 | * Implementation for BIGINT, INTEGER, SMALLINT 4 | */ 5 | 6 | -- BIGINT implementation 7 | CREATE OR REPLACE FUNCTION array_sum(a BIGINT[]) RETURNS BIGINT AS $$ 8 | DECLARE 9 | res BIGINT; 10 | BEGIN 11 | 12 | WITH unnested AS 13 | ( 14 | SELECT UNNEST(a) AS vals 15 | ) 16 | SELECT sum(vals) FROM unnested AS x INTO res; 17 | 18 | RETURN res; 19 | 20 | END; 21 | $$ 22 | STRICT 23 | LANGUAGE plpgsql IMMUTABLE 24 | ; 25 | COMMENT ON FUNCTION array_sum(a BIGINT[]) IS 'Returns the sum of values of a BIGINT array'; 26 | 27 | -- INTEGER implementation 28 | CREATE OR REPLACE FUNCTION array_sum(a INTEGER[]) RETURNS BIGINT AS $$ 29 | DECLARE 30 | res BIGINT; 31 | BEGIN 32 | 33 | WITH unnested AS 34 | ( 35 | SELECT UNNEST(a) AS vals 36 | ) 37 | SELECT sum(vals) FROM unnested AS x INTO res; 38 | 39 | RETURN res; 40 | 41 | END; 42 | $$ 43 | STRICT 44 | LANGUAGE plpgsql IMMUTABLE 45 | ; 46 | COMMENT ON FUNCTION array_sum(a INTEGER[]) IS 'Returns the sum of values of an INTEGER array'; 47 | 48 | -- SMALLINT implementation 49 | CREATE OR REPLACE FUNCTION array_sum(a SMALLINT[]) RETURNS BIGINT AS $$ 50 | DECLARE 51 | res BIGINT; 52 | BEGIN 53 | 54 | WITH unnested AS 55 | ( 56 | SELECT UNNEST(a) AS vals 57 | ) 58 | SELECT sum(vals) FROM unnested AS x INTO res; 59 | 60 | RETURN res; 61 | 62 | END; 63 | $$ 64 | STRICT 65 | LANGUAGE plpgsql IMMUTABLE 66 | ; 67 | COMMENT ON FUNCTION array_sum(a SMALLINT[]) IS 'Returns the sum of values of a SMALLINT array'; 68 | 69 | -- REAL implementation 70 | CREATE OR REPLACE FUNCTION array_sum(a REAL[]) RETURNS NUMERIC AS $$ 71 | DECLARE 72 | res NUMERIC; 73 | BEGIN 74 | 75 | WITH unnested AS 76 | ( 77 | SELECT UNNEST(a) AS vals 78 | ) 79 | SELECT sum(vals) FROM unnested AS x INTO res; 80 | 81 | RETURN res; 82 | 83 | END; 84 | $$ 85 | STRICT 86 | LANGUAGE plpgsql IMMUTABLE 87 | ; 88 | COMMENT ON FUNCTION array_sum(a REAL[]) IS 'Returns the sum of values of a REAL array'; 89 | 90 | -- DOUBLE PRECISION implementation 91 | CREATE OR REPLACE FUNCTION array_sum(a DOUBLE PRECISION[]) RETURNS NUMERIC AS $$ 92 | DECLARE 93 | res NUMERIC; 94 | BEGIN 95 | 96 | WITH unnested AS 97 | ( 98 | SELECT UNNEST(a) AS vals 99 | ) 100 | SELECT sum(vals) FROM unnested AS x INTO res; 101 | 102 | RETURN res; 103 | 104 | END; 105 | $$ 106 | STRICT 107 | LANGUAGE plpgsql IMMUTABLE 108 | ; 109 | COMMENT ON FUNCTION array_sum(a DOUBLE PRECISION[]) IS 'Returns the sum of values of a DOUBLE PRECISION array'; 110 | 111 | -- NUMERIC implementation 112 | CREATE OR REPLACE FUNCTION array_sum(a NUMERIC[]) RETURNS NUMERIC AS $$ 113 | DECLARE 114 | res NUMERIC; 115 | BEGIN 116 | 117 | WITH unnested AS 118 | ( 119 | SELECT UNNEST(a) AS vals 120 | ) 121 | SELECT sum(vals) FROM unnested AS x INTO res; 122 | 123 | RETURN res; 124 | 125 | END; 126 | $$ 127 | STRICT 128 | LANGUAGE plpgsql IMMUTABLE 129 | ; 130 | COMMENT ON FUNCTION array_sum(a NUMERIC[]) IS 'Returns the sum of values of a NUMERIC array'; 131 | -------------------------------------------------------------------------------- /sql/function_date_de.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function which returns the given date in German format. 3 | */ 4 | CREATE OR REPLACE FUNCTION date_de(d DATE) RETURNS text AS $$ 5 | BEGIN 6 | RETURN to_char(d, 'DD.MM.YYYY'); 7 | END; 8 | $$ 9 | STRICT 10 | LANGUAGE plpgsql IMMUTABLE; 11 | COMMENT ON FUNCTION date_de(d DATE) IS 'Creates a function which returns the given date in German format'; 12 | -------------------------------------------------------------------------------- /sql/function_datetime_de.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function which returns the given timestamp in German format. 3 | * The second parameter indicates, if the result is with or without time zone, 4 | * default is with thime zone 5 | */ 6 | CREATE OR REPLACE FUNCTION datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN DEFAULT TRUE) RETURNS text AS $$ 7 | BEGIN 8 | IF with_tz THEN 9 | RETURN to_char(t, 'DD.MM.YYYY HH24:MI:SS TZ'); 10 | ELSE 11 | RETURN to_char(t, 'DD.MM.YYYY HH24:MI:SS'); 12 | END IF; 13 | END; 14 | $$ 15 | STRICT 16 | LANGUAGE plpgsql IMMUTABLE; 17 | COMMENT ON FUNCTION datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN) IS 'Creates a function which returns the given timestamp in German format'; 18 | -------------------------------------------------------------------------------- /sql/function_hex2bigint.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to convert a hexadicimal number given as string into a BIGINT. 3 | */ 4 | CREATE OR REPLACE FUNCTION hex2bigint(s TEXT) RETURNS BIGINT AS $$ 5 | WITH RECURSIVE hex_sep AS 6 | ( 7 | SELECT 8 | cast (cast (cast ('x0' || substring (s, length (s), 1) AS BIT(8)) AS INT) * POWER(16, 0) AS BIGINT ) int_res 9 | , substring (s, 1 , length (s) - 1) AS rest 10 | , length (s) - 1 AS len 11 | , 1 AS row_num 12 | UNION ALL 13 | SELECT 14 | cast (cast (cast ('x0' || substring (rest, length (rest), 1) AS BIT(8)) AS INT) * POWER(16, row_num) AS BIGINT) int_res 15 | , substring (rest, 1 , length (rest) - 1) AS rest 16 | , length (rest) - 1 AS len 17 | , row_num + 1 AS row_num 18 | FROM hex_sep 19 | WHERE len > 0 20 | ) 21 | SELECT cast (sum(int_res)AS BIGINT) 22 | FROM hex_sep 23 | ; 24 | $$ LANGUAGE sql IMMUTABLE STRICT 25 | ; 26 | COMMENT ON FUNCTION hex2bigint(s TEXT) IS 'Converts a hexadicimal number given as string into a BIGINT'; 27 | -------------------------------------------------------------------------------- /sql/function_is_bigint.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to check strings for being BIGINT. 3 | */ 4 | CREATE OR REPLACE FUNCTION is_bigint(s text) RETURNS BOOLEAN AS $$ 5 | BEGIN 6 | PERFORM s::BIGINT; 7 | RETURN TRUE; 8 | EXCEPTION WHEN others THEN 9 | RETURN FALSE; 10 | END; 11 | $$ 12 | STRICT 13 | LANGUAGE plpgsql IMMUTABLE 14 | ; 15 | COMMENT ON FUNCTION is_bigint(s text) IS 'Checks, whether the given parameter is a BIGINT'; 16 | -------------------------------------------------------------------------------- /sql/function_is_bigint_array.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to check strings for being a BIGINT array. 3 | */ 4 | CREATE OR REPLACE FUNCTION is_bigint_array(s text) RETURNS BOOLEAN AS $$ 5 | BEGIN 6 | PERFORM s::BIGINT[]; 7 | RETURN TRUE; 8 | EXCEPTION WHEN others THEN 9 | RETURN FALSE; 10 | END; 11 | $$ 12 | STRICT 13 | LANGUAGE plpgsql IMMUTABLE 14 | ; 15 | COMMENT ON FUNCTION is_bigint_array(s text) IS 'Checks, whether the given parameter is a BIGINT array'; 16 | -------------------------------------------------------------------------------- /sql/function_is_boolean.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to check strings for being BOOLEAN. 3 | */ 4 | CREATE OR REPLACE FUNCTION is_boolean(s text) RETURNS BOOLEAN AS $$ 5 | BEGIN 6 | PERFORM s::BOOLEAN; 7 | RETURN TRUE; 8 | EXCEPTION WHEN others THEN 9 | RETURN FALSE; 10 | END; 11 | $$ 12 | STRICT 13 | LANGUAGE plpgsql IMMUTABLE 14 | ; 15 | COMMENT ON FUNCTION is_boolean(s text) IS 'Checks, whether the given parameter is a BOOLEAN'; 16 | -------------------------------------------------------------------------------- /sql/function_is_date.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates two functions to check strings for being a date. 3 | * The first function checks it with the default format, the second with the 4 | * format given as parameter. 5 | */ 6 | CREATE OR REPLACE FUNCTION is_date(s text) RETURNS BOOLEAN AS $$ 7 | BEGIN 8 | PERFORM s::date; 9 | RETURN TRUE; 10 | EXCEPTION WHEN OTHERS THEN 11 | RETURN FALSE; 12 | END; 13 | $$ 14 | STRICT 15 | LANGUAGE plpgsql IMMUTABLE 16 | ; 17 | COMMENT ON FUNCTION is_date(s text) IS 'Takes a text and checks if it is a date, uses standard date format YYYY-MM-DD'; 18 | 19 | 20 | CREATE OR REPLACE FUNCTION is_date(s text, f text) RETURNS BOOLEAN AS $$ 21 | BEGIN 22 | PERFORM to_date(s, f); 23 | RETURN TRUE; 24 | EXCEPTION WHEN OTHERS THEN 25 | RETURN FALSE; 26 | END; 27 | $$ 28 | STRICT 29 | LANGUAGE plpgsql IMMUTABLE 30 | ; 31 | COMMENT ON FUNCTION is_date(s text, f text) IS 'Takes a text and checks if it is a date by taking the second text as date format'; 32 | -------------------------------------------------------------------------------- /sql/function_is_double_precision.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to check strings for being INTEGER. 3 | */ 4 | CREATE OR REPLACE FUNCTION is_double_precision(s text) RETURNS BOOLEAN AS $$ 5 | BEGIN 6 | PERFORM s::DOUBLE PRECISION; 7 | RETURN TRUE; 8 | EXCEPTION WHEN others THEN 9 | RETURN FALSE; 10 | END; 11 | $$ 12 | STRICT 13 | LANGUAGE plpgsql IMMUTABLE 14 | ; 15 | COMMENT ON FUNCTION is_double_precision(s text) IS 'Checks, whether the given parameter is a DOUBLE PRECISION'; 16 | -------------------------------------------------------------------------------- /sql/function_is_empty.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to checks a string variable for being either, NULL or ''. 3 | * The function is installed with a different name, is_empty_b when the 4 | * extension pgtap is installed as it also has an is_empty function, but with 5 | * a different implementation. 6 | * The b in is_empty_b stands for the boolean result, that the function is 7 | * returning. 8 | */ 9 | DO $$ 10 | DECLARE 11 | pg_extension_installed BOOLEAN; 12 | function_source TEXT; 13 | BEGIN 14 | 15 | SELECT count(*) pgtap_exists FROM pg_extension WHERE extname = 'pgtap' INTO pg_extension_installed; 16 | 17 | IF NOT pg_extension_installed THEN 18 | -- pgtap is not installed, is_empty will be installed 19 | function_source := 20 | $string$ 21 | CREATE OR REPLACE FUNCTION is_empty(s text) RETURNS BOOLEAN AS $f1$ 22 | BEGIN 23 | RETURN COALESCE(s, '') = ''; 24 | END; 25 | $f1$ 26 | LANGUAGE plpgsql IMMUTABLE 27 | ; 28 | $string$ 29 | ; 30 | EXECUTE function_source; 31 | 32 | COMMENT ON FUNCTION is_empty(s text) IS 'Checks, whether the given parameter is NULL or '''''; 33 | ELSE 34 | -- pgtap is installed, is_empty will be installed as is_empty_b 35 | function_source := 36 | $string$ 37 | CREATE OR REPLACE FUNCTION is_empty_b(s text) RETURNS BOOLEAN AS $f1$ 38 | BEGIN 39 | RETURN COALESCE(s, '') = ''; 40 | END; 41 | $f1$ 42 | LANGUAGE plpgsql IMMUTABLE 43 | ; 44 | $string$ 45 | ; 46 | EXECUTE function_source; 47 | 48 | COMMENT ON FUNCTION is_empty_b(s text) IS 'Checks, whether the given parameter is NULL or '''''; 49 | END IF; 50 | 51 | END $$; 52 | -------------------------------------------------------------------------------- /sql/function_is_encoding.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates two functions to check strings about encodings. 3 | * The first function checks if an UTF-8 string does only contain characters 4 | * in the given second parameter. 5 | * The second parameter takes as third parameter the encoding in which the 6 | * string is and checks if the string does only contain characters as given in 7 | * the second parameter. 8 | */ 9 | CREATE OR REPLACE FUNCTION is_encoding(s text, enc text) RETURNS BOOLEAN AS $$ 10 | BEGIN 11 | PERFORM convert(s::bytea, 'UTF8', enc); 12 | RETURN TRUE; 13 | EXCEPTION WHEN others THEN 14 | RETURN FALSE; 15 | END; 16 | $$ 17 | STRICT 18 | LANGUAGE plpgsql IMMUTABLE 19 | ; 20 | COMMENT ON FUNCTION is_encoding(s text, enc text) IS 'Checks, whether the given UTF8 sting contains only encodings in the given encoding characters'; 21 | 22 | 23 | CREATE OR REPLACE FUNCTION is_encoding(s text, enc text, enc_from text) RETURNS BOOLEAN AS $$ 24 | BEGIN 25 | PERFORM convert(s::bytea, enc_from, enc); 26 | RETURN TRUE; 27 | EXCEPTION WHEN others THEN 28 | RETURN FALSE; 29 | END; 30 | $$ 31 | STRICT 32 | LANGUAGE plpgsql IMMUTABLE 33 | ; 34 | COMMENT ON FUNCTION is_encoding(s text, enc text, enc_from text) IS 'Checks, whether the given encoding sting contains only encodings in the given encoding characters'; 35 | -------------------------------------------------------------------------------- /sql/function_is_hex.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to check hexadeciaml numbers passed as strings for being hexadeciaml fitting into a 0BIGINT. 3 | */ 4 | CREATE OR REPLACE FUNCTION is_hex(s TEXT) RETURNS BOOLEAN AS $$ 5 | BEGIN 6 | PERFORM hex2bigint (s); 7 | RETURN TRUE; 8 | EXCEPTION WHEN others THEN 9 | RETURN FALSE; 10 | END; 11 | $$ 12 | STRICT 13 | LANGUAGE plpgsql IMMUTABLE 14 | ; 15 | COMMENT ON FUNCTION is_hex(s TEXT) IS 'Checks, whether the given parameter is a hexadeciaml number fitting into a BIGINT'; 16 | -------------------------------------------------------------------------------- /sql/function_is_integer.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to check strings for being INTEGER. 3 | */ 4 | CREATE OR REPLACE FUNCTION is_integer(s text) RETURNS BOOLEAN AS $$ 5 | BEGIN 6 | PERFORM s::INTEGER; 7 | RETURN TRUE; 8 | EXCEPTION WHEN others THEN 9 | RETURN FALSE; 10 | END; 11 | $$ 12 | STRICT 13 | LANGUAGE plpgsql IMMUTABLE 14 | ; 15 | COMMENT ON FUNCTION is_integer(s text) IS 'Checks, whether the given parameter is an INTEGER'; 16 | -------------------------------------------------------------------------------- /sql/function_is_integer_array.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to check strings for being an INTEGER array. 3 | */ 4 | CREATE OR REPLACE FUNCTION is_integer_array(s text) RETURNS BOOLEAN AS $$ 5 | BEGIN 6 | PERFORM s::INTEGER[]; 7 | RETURN TRUE; 8 | EXCEPTION WHEN others THEN 9 | RETURN FALSE; 10 | END; 11 | $$ 12 | STRICT 13 | LANGUAGE plpgsql IMMUTABLE 14 | ; 15 | COMMENT ON FUNCTION is_integer_array(s text) IS 'Checks, whether the given parameter is an INTEGER array'; 16 | -------------------------------------------------------------------------------- /sql/function_is_json.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to check strings for being JSON. 3 | */ 4 | CREATE OR REPLACE FUNCTION is_json(s text) RETURNS BOOLEAN AS $$ 5 | BEGIN 6 | PERFORM s::JSON; 7 | RETURN TRUE; 8 | EXCEPTION WHEN others THEN 9 | RETURN FALSE; 10 | END; 11 | $$ 12 | STRICT 13 | LANGUAGE plpgsql IMMUTABLE 14 | ; 15 | COMMENT ON FUNCTION is_json(s text) IS 'Checks, whether the given text is a JSON'; 16 | -------------------------------------------------------------------------------- /sql/function_is_jsonb.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to check strings for being JSONB. 3 | */ 4 | CREATE OR REPLACE FUNCTION is_jsonb(s text) RETURNS BOOLEAN AS $$ 5 | BEGIN 6 | PERFORM s::JSONB; 7 | RETURN TRUE; 8 | EXCEPTION WHEN others THEN 9 | RETURN FALSE; 10 | END; 11 | $$ 12 | STRICT 13 | LANGUAGE plpgsql IMMUTABLE 14 | ; 15 | COMMENT ON FUNCTION is_jsonb(s text) IS 'Checks, whether the given text is a JSONB'; 16 | -------------------------------------------------------------------------------- /sql/function_is_latin1.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to check UTF-8 strings for containing only Latin1 3 | * characters. 4 | */ 5 | CREATE OR REPLACE FUNCTION is_latin1(s text) RETURNS BOOLEAN AS $$ 6 | BEGIN 7 | PERFORM convert(s::bytea, 'UTF8', 'LATIN1'); 8 | RETURN TRUE; 9 | EXCEPTION WHEN others THEN 10 | RETURN FALSE; 11 | END; 12 | $$ 13 | STRICT 14 | LANGUAGE plpgsql IMMUTABLE 15 | ; 16 | COMMENT ON FUNCTION is_latin1(s text) IS 'Checks, whether the given parameter contains only latin1 characters'; 17 | -------------------------------------------------------------------------------- /sql/function_is_numeric.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to check strings for being nunbers. 3 | */ 4 | CREATE OR REPLACE FUNCTION is_numeric(s text) RETURNS BOOLEAN AS $$ 5 | BEGIN 6 | PERFORM s::NUMERIC; 7 | RETURN TRUE; 8 | EXCEPTION WHEN others THEN 9 | RETURN FALSE; 10 | END; 11 | $$ 12 | STRICT 13 | LANGUAGE plpgsql IMMUTABLE 14 | ; 15 | COMMENT ON FUNCTION is_numeric(s text) IS 'Checks, whether the given parameter is a number'; 16 | -------------------------------------------------------------------------------- /sql/function_is_real.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to check strings for being INTEGER. 3 | */ 4 | CREATE OR REPLACE FUNCTION is_real(s text) RETURNS BOOLEAN AS $$ 5 | BEGIN 6 | PERFORM s::REAL; 7 | RETURN TRUE; 8 | EXCEPTION WHEN others THEN 9 | RETURN FALSE; 10 | END; 11 | $$ 12 | STRICT 13 | LANGUAGE plpgsql IMMUTABLE 14 | ; 15 | COMMENT ON FUNCTION is_real(s text) IS 'Checks, whether the given parameter is a REAL'; 16 | -------------------------------------------------------------------------------- /sql/function_is_smallint.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to check strings for being SMALLINT. 3 | */ 4 | CREATE OR REPLACE FUNCTION is_smallint(s text) RETURNS BOOLEAN AS $$ 5 | BEGIN 6 | PERFORM s::SMALLINT; 7 | RETURN TRUE; 8 | EXCEPTION WHEN others THEN 9 | RETURN FALSE; 10 | END; 11 | $$ 12 | STRICT 13 | LANGUAGE plpgsql IMMUTABLE 14 | ; 15 | COMMENT ON FUNCTION is_smallint(s text) IS 'Checks, whether the given parameter is a smallint'; 16 | -------------------------------------------------------------------------------- /sql/function_is_smallint_array.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to check strings for being an SMALLINT array. 3 | */ 4 | CREATE OR REPLACE FUNCTION is_smallint_array(s text) RETURNS BOOLEAN AS $$ 5 | BEGIN 6 | PERFORM s::SMALLINT[]; 7 | RETURN TRUE; 8 | EXCEPTION WHEN others THEN 9 | RETURN FALSE; 10 | END; 11 | $$ 12 | STRICT 13 | LANGUAGE plpgsql IMMUTABLE 14 | ; 15 | COMMENT ON FUNCTION is_smallint_array(s text) IS 'Checks, whether the given parameter is a SMALLINT array'; 16 | -------------------------------------------------------------------------------- /sql/function_is_text_array.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to check strings for being an SMALLINT array. 3 | */ 4 | CREATE OR REPLACE FUNCTION is_text_array(s text) RETURNS BOOLEAN AS $$ 5 | BEGIN 6 | PERFORM s::TEXT[]; 7 | RETURN TRUE; 8 | EXCEPTION WHEN others THEN 9 | RETURN FALSE; 10 | END; 11 | $$ 12 | STRICT 13 | LANGUAGE plpgsql IMMUTABLE 14 | ; 15 | COMMENT ON FUNCTION is_text_array(s text) IS 'Checks, whether the given parameter is a TEXT array'; 16 | -------------------------------------------------------------------------------- /sql/function_is_time.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates two functions to check strings for being a time. 3 | * The first function checks it with the default format, the second with the 4 | * format given as parameter. 5 | */ 6 | CREATE OR REPLACE FUNCTION is_time(s text) RETURNS BOOLEAN AS $$ 7 | BEGIN 8 | PERFORM s::TIME; 9 | RETURN TRUE; 10 | EXCEPTION WHEN OTHERS THEN 11 | RETURN FALSE; 12 | END; 13 | $$ 14 | STRICT 15 | LANGUAGE plpgsql IMMUTABLE 16 | ; 17 | COMMENT ON FUNCTION is_time(s text) IS 'Takes a text and checks if it is a time, uses standard date format HH24:MI:SS.US'; 18 | 19 | 20 | CREATE OR REPLACE FUNCTION is_time(s text, f text) RETURNS BOOLEAN AS $$ 21 | BEGIN 22 | PERFORM to_timestamp(s, f)::TIME; 23 | RETURN TRUE; 24 | EXCEPTION WHEN OTHERS THEN 25 | RETURN FALSE; 26 | END; 27 | $$ 28 | STRICT 29 | LANGUAGE plpgsql IMMUTABLE 30 | ; 31 | COMMENT ON FUNCTION is_time(s text, f text) IS 'Takes a text and checks if it is a time by taking the second text as time format'; 32 | -------------------------------------------------------------------------------- /sql/function_is_timestamp.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates two functions to check strings for being timestamps. 3 | * The first function checks it with the default format, the second with the 4 | * format given as parameter. 5 | */ 6 | CREATE OR REPLACE FUNCTION is_timestamp(s text) RETURNS BOOLEAN AS $$ 7 | BEGIN 8 | PERFORM s::TIMESTAMP; 9 | RETURN TRUE; 10 | EXCEPTION WHEN others THEN 11 | RETURN FALSE; 12 | END; 13 | $$ 14 | STRICT 15 | LANGUAGE plpgsql IMMUTABLE; 16 | COMMENT ON FUNCTION is_timestamp(s text) IS 'Takes a text and checks if it is a timestamp, uses standard timestamp format YYYY-MM-DD HH24:MI:SS'; 17 | 18 | 19 | CREATE OR REPLACE FUNCTION is_timestamp(s text, f text) RETURNS BOOLEAN AS $$ 20 | BEGIN 21 | PERFORM to_timestamp(s, f)::TIMESTAMP; 22 | RETURN TRUE; 23 | EXCEPTION WHEN others THEN 24 | RETURN FALSE; 25 | END; 26 | $$ 27 | STRICT 28 | LANGUAGE plpgsql IMMUTABLE; 29 | COMMENT ON FUNCTION is_timestamp(s text) IS 'Takes a text and checks if it is a timestamp by taking the second text as date format'; 30 | -------------------------------------------------------------------------------- /sql/function_is_uuid.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function to check strings for being UUID. 3 | */ 4 | CREATE OR REPLACE FUNCTION is_uuid(s text) RETURNS BOOLEAN AS $$ 5 | BEGIN 6 | PERFORM s::UUID; 7 | RETURN TRUE; 8 | EXCEPTION WHEN others THEN 9 | RETURN FALSE; 10 | END; 11 | $$ 12 | STRICT 13 | LANGUAGE plpgsql IMMUTABLE 14 | ; 15 | COMMENT ON FUNCTION is_uuid(s text) IS 'Checks, whether the given parameter is a uuid'; 16 | -------------------------------------------------------------------------------- /sql/function_pg_schema_size.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function which returns the size of a schema. 3 | */ 4 | CREATE OR REPLACE FUNCTION pg_schema_size(text) RETURNS BIGINT AS $$ 5 | SELECT SUM(pg_total_relation_size(quote_ident(schemaname) || '.' || quote_ident(tablename)))::BIGINT 6 | FROM pg_tables 7 | WHERE schemaname = $1 8 | $$ LANGUAGE SQL STRICT IMMUTABLE; 9 | COMMENT ON FUNCTION pg_schema_size(text) IS 'Returns the size for given schema name'; 10 | -------------------------------------------------------------------------------- /sql/function_replace_encoding.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates three function to replace characters, that are not part of the given 3 | * encoding. 4 | * The function does depend on the function is_encoding which is part of this 5 | * repository. 6 | */ 7 | CREATE OR REPLACE FUNCTION replace_encoding(s text, e text) RETURNS text AS $$ 8 | DECLARE 9 | i INTEGER := 0; 10 | res text; 11 | BEGIN 12 | res := s; 13 | 14 | LOOP 15 | EXIT WHEN i > length(res); 16 | i := i + 1; 17 | IF (NOT is_encoding(substring(res FROM i FOR 1 ), e)) THEN 18 | res := OVERLAY(res PLACING '' FROM i FOR 1); 19 | END IF; 20 | END LOOP; 21 | 22 | RETURN res; 23 | END; 24 | $$ 25 | STRICT 26 | LANGUAGE plpgsql IMMUTABLE 27 | ; 28 | COMMENT ON FUNCTION replace_encoding(s text, e text) IS 'Replaces all characters, which are not part of the given encoding, with spaces and returns the result only with characters which are part of the given encoding'; 29 | 30 | 31 | CREATE OR REPLACE FUNCTION replace_encoding(s text, e text, replacement text) RETURNS text AS $$ 32 | DECLARE 33 | i INTEGER := 0; 34 | res text; 35 | BEGIN 36 | res := s; 37 | 38 | LOOP 39 | EXIT WHEN i > length(res); 40 | i := i + 1; 41 | IF (NOT is_encoding(substring(res FROM i FOR 1 ), e)) THEN 42 | res := OVERLAY(res PLACING replacement FROM i FOR 1); 43 | END IF; 44 | END LOOP; 45 | 46 | RETURN res; 47 | END; 48 | $$ 49 | STRICT 50 | LANGUAGE plpgsql IMMUTABLE 51 | ; 52 | COMMENT ON FUNCTION replace_encoding(s text, e text, replacement text) IS 'Replaces all characters, which are not part of the given encoding, with the given replacement in the third parameter and returns the result only with characters which are part of the given encoding'; 53 | 54 | 55 | CREATE OR REPLACE FUNCTION replace_encoding(s text, s_search text[], s_replace text[]) RETURNS text AS $$ 56 | DECLARE 57 | i INTEGER := 0; 58 | res text; 59 | length_equal BOOLEAN; 60 | a_count INTEGER; 61 | BEGIN 62 | 63 | SELECT array_length(s_search, 1) = array_length(s_replace, 1) INTO length_equal; 64 | 65 | IF NOT length_equal THEN 66 | RAISE 'Search and replacement arrays do not have the same count of entries' USING ERRCODE = '22000'; 67 | END IF; 68 | 69 | SELECT array_length(s_search, 1) INTO a_count; 70 | res := s; 71 | 72 | LOOP 73 | EXIT WHEN i >= a_count; 74 | i := i + 1; 75 | 76 | res := REPLACE(res, s_search[i], s_replace[i]); 77 | 78 | END LOOP; 79 | 80 | RETURN res; 81 | 82 | END; 83 | $$ 84 | STRICT 85 | LANGUAGE plpgsql IMMUTABLE 86 | ; 87 | COMMENT ON FUNCTION replace_encoding(s text, s_search text[], s_replace text[]) IS 'Replaces charactes given in s_search with characters given in s_replace at the same array position'; 88 | -------------------------------------------------------------------------------- /sql/function_replace_latin1.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates two function to replace characters, that are not part of latin1. 3 | * The function does depend on the function is_latin1 which is part of this 4 | * repository. 5 | */ 6 | CREATE OR REPLACE FUNCTION replace_latin1(s text) RETURNS text AS $$ 7 | DECLARE 8 | i INTEGER := 0; 9 | res text; 10 | BEGIN 11 | res := s; 12 | 13 | LOOP 14 | EXIT WHEN i > length(res); 15 | i := i + 1; 16 | IF (NOT is_latin1(substring(res FROM i FOR 1 ))) THEN 17 | res := OVERLAY(res PLACING '' FROM i FOR 1); 18 | END IF; 19 | END LOOP; 20 | 21 | RETURN res; 22 | END; 23 | $$ 24 | STRICT 25 | LANGUAGE plpgsql IMMUTABLE 26 | ; 27 | COMMENT ON FUNCTION replace_latin1(s text) IS 'Replaces all not latin1 characters with spaces and returns the result with only containing latin1 characters'; 28 | 29 | 30 | CREATE OR REPLACE FUNCTION replace_latin1(s text, replacement text) RETURNS text AS $$ 31 | DECLARE 32 | i INTEGER := 0; 33 | res text; 34 | BEGIN 35 | res := s; 36 | 37 | LOOP 38 | EXIT WHEN i > length(res); 39 | i := i + 1; 40 | IF (NOT is_latin1(substring(res FROM i FOR 1 ))) THEN 41 | res := OVERLAY(res PLACING replacement FROM i FOR 1); 42 | END IF; 43 | END LOOP; 44 | 45 | RETURN res; 46 | END; 47 | $$ 48 | STRICT 49 | LANGUAGE plpgsql IMMUTABLE 50 | ; 51 | COMMENT ON FUNCTION replace_latin1(s text, replacement text) IS 'Replaces all not latin1 characters with the given replacement in the second parameter and returns the result with only containing latin1 characters'; 52 | 53 | 54 | CREATE OR REPLACE FUNCTION replace_latin1(s text, s_search text[], s_replace text[]) RETURNS text AS $$ 55 | DECLARE 56 | res text; 57 | BEGIN 58 | 59 | SELECT replace_encoding(s, s_search, s_replace) INTO res; 60 | 61 | RETURN res; 62 | 63 | END; 64 | $$ 65 | STRICT 66 | LANGUAGE plpgsql IMMUTABLE 67 | ; 68 | COMMENT ON FUNCTION replace_latin1(s text, s_search text[], s_replace text[]) IS 'Replaces charactes given in s_search with characters given in s_replace at the same array position. The function is an alias for replace_encoding.'; 69 | -------------------------------------------------------------------------------- /sql/function_return_not_part_of_encoding.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function which returns a distinct array with all non latin1 characters . 3 | */ 4 | CREATE OR REPLACE FUNCTION return_not_part_of_encoding(s text, e text) RETURNS text[] AS $$ 5 | DECLARE 6 | i INTEGER := 0; 7 | res text[]; 8 | current_s text := NULL::text[]; 9 | BEGIN 10 | 11 | LOOP 12 | EXIT WHEN i > length(s); 13 | i := i + 1; 14 | current_s := substring(s FROM i FOR 1); 15 | IF (NOT is_encoding(current_s, e)) THEN 16 | SELECT array_append(res, current_s) INTO res; 17 | END IF; 18 | END LOOP; 19 | 20 | WITH t1 AS 21 | ( 22 | SELECT unnest(res) AS c1 23 | ) 24 | , t2 AS 25 | ( 26 | SELECT DISTINCT c1 27 | FROM t1 28 | ) 29 | , t3 AS 30 | ( 31 | SELECT array_agg(c1) AS res_array 32 | FROM t2 33 | ) 34 | SELECT res_array 35 | FROM t3 36 | INTO res; 37 | 38 | RETURN res; 39 | END; 40 | $$ 41 | STRICT 42 | LANGUAGE plpgsql IMMUTABLE 43 | ; 44 | COMMENT ON FUNCTION return_not_part_of_encoding(s text, e text) IS 'Creates a function which returns a distinct array with all characters which are not part of the encoding give in e'; 45 | -------------------------------------------------------------------------------- /sql/function_return_not_part_of_latin1.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function which returns a distinct array with all non latin1 3 | * characters . Depends on function is_latin1 which is part of this repository. 4 | */ 5 | CREATE OR REPLACE FUNCTION return_not_part_of_latin1(s text) RETURNS text[] AS $$ 6 | DECLARE 7 | i INTEGER := 0; 8 | res text[]; 9 | current_s text := NULL::text[]; 10 | BEGIN 11 | 12 | LOOP 13 | EXIT WHEN i > length(s); 14 | i := i + 1; 15 | current_s := substring(s FROM i FOR 1); 16 | IF (NOT is_latin1(current_s)) THEN 17 | SELECT array_append(res, current_s) INTO res; 18 | END IF; 19 | END LOOP; 20 | 21 | WITH t1 AS 22 | ( 23 | SELECT unnest(res) AS c1 24 | ) 25 | , t2 AS 26 | ( 27 | SELECT DISTINCT c1 28 | FROM t1 29 | ) 30 | , t3 AS 31 | ( 32 | SELECT array_agg(c1) AS res_array 33 | FROM t2 34 | ) 35 | SELECT res_array 36 | FROM t3 37 | INTO res; 38 | 39 | RETURN res; 40 | END; 41 | $$ 42 | STRICT 43 | LANGUAGE plpgsql IMMUTABLE 44 | ; 45 | COMMENT ON FUNCTION return_not_part_of_latin1(s text) IS 'Creates a function which returns a distinct array with all non latin1 characters'; 46 | -------------------------------------------------------------------------------- /sql/function_sha256.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a function which returns a SHA256 hash for the given string. 3 | * 4 | * The function needs the pgcrypto package, this is checked on the installation. 5 | */ 6 | DO $$ 7 | DECLARE 8 | pg_extension_installed BOOLEAN; 9 | function_source TEXT; 10 | BEGIN 11 | 12 | SELECT count(*) = 1 AS pgcrypto_installed FROM pg_extension WHERE extname = 'pgcrypto' INTO pg_extension_installed; 13 | 14 | IF pg_extension_installed THEN 15 | -- The pgcrypto extension is installed, sha256 will be installed 16 | function_source := 17 | $string$ 18 | CREATE OR REPLACE FUNCTION sha256(bytea) RETURNS text AS $f1$ 19 | SELECT ENCODE(digest($1, 'sha256'), 'hex') 20 | $f1$ LANGUAGE SQL STRICT IMMUTABLE 21 | ; 22 | $string$ 23 | ; 24 | 25 | EXECUTE function_source; 26 | 27 | COMMENT ON FUNCTION sha256(bytea) IS 'Returns a SHA254 hash for the given string'; 28 | END IF; 29 | 30 | END $$; 31 | -------------------------------------------------------------------------------- /sql/function_to_unix_timestamp.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates two functions which returns unix timestamp for the a given timestamp 3 | * or a given timestamp with time zone. 4 | * 5 | * The function needs the pgcrypto package. 6 | */ 7 | CREATE OR REPLACE FUNCTION to_unix_timestamp(ts timestamp) RETURNS bigint AS $$ 8 | SELECT EXTRACT (EPOCH FROM ts)::bigint; 9 | $$ LANGUAGE SQL STRICT IMMUTABLE 10 | ; 11 | COMMENT ON FUNCTION to_unix_timestamp(ts timestamp) IS 'Returns an unix timestamp for the given timestamp'; 12 | 13 | CREATE OR REPLACE FUNCTION to_unix_timestamp(ts timestamp with time zone) RETURNS bigint AS $$ 14 | SELECT EXTRACT (EPOCH FROM ts)::bigint; 15 | $$ LANGUAGE SQL STRICT IMMUTABLE 16 | ; 17 | COMMENT ON FUNCTION to_unix_timestamp(ts timestamp with time zone) IS 'Returns an unix timestamp for the given timestamp with time zone'; 18 | -------------------------------------------------------------------------------- /sql/gab_fill.sql: -------------------------------------------------------------------------------- 1 | -- Create a window function to calculate values for gaps 2 | CREATE OR REPLACE FUNCTION GapFillInternal(s anyelement, v anyelement) 3 | RETURNS anyelement AS 4 | $$ 5 | BEGIN 6 | RETURN COALESCE(v, s); 7 | END; 8 | $$ LANGUAGE PLPGSQL IMMUTABLE; 9 | COMMENT ON FUNCTION GapFillInternal(s anyelement, v anyelement) IS 'The function is used to fill gaps in window functions'; 10 | 11 | 12 | -- The Window function needs an aggregate 13 | CREATE AGGREGATE GapFill(anyelement) ( 14 | SFUNC=GapFillInternal, 15 | STYPE = anyelement 16 | ) 17 | ; 18 | COMMENT ON AGGREGATE GapFill(anyelement) IS 'Implements the aggregate function to fill gaps using the function GapFillInternal'; 19 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.1.0.sql: -------------------------------------------------------------------------------- 1 | SET client_min_messages TO warning; 2 | SET log_min_messages TO warning; 3 | 4 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 5 | 6 | BEGIN; 7 | 8 | DROP VIEW IF EXISTS pg_active_locks; 9 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 11 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 12 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 13 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 14 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 15 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 16 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 17 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 18 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 19 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 24 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 25 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 26 | DROP FUNCTION IF EXISTS date_de(d DATE); 27 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 28 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 29 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 30 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, replacement VARCHAR); 31 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR); 32 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 33 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR, replacement VARCHAR); 34 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR); 35 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s VARCHAR, e VARCHAR); 36 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s VARCHAR); 37 | DROP FUNCTION IF EXISTS is_latin1(s VARCHAR); 38 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR, enc_from VARCHAR); 39 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR); 40 | DROP VIEW IF EXISTS pg_functions; 41 | DROP VIEW IF EXISTS pg_foreign_keys; 42 | DROP VIEW IF EXISTS pg_db_views; 43 | DROP FUNCTION IF EXISTS pg_schema_size(text); 44 | DROP FUNCTION IF EXISTS sha256(bytea); 45 | DROP FUNCTION IF EXISTS is_integer(s VARCHAR); 46 | DROP FUNCTION IF EXISTS is_numeric(s VARCHAR); 47 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR, f VARCHAR); 48 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR); 49 | DROP FUNCTION IF EXISTS is_time(s VARCHAR, f VARCHAR); 50 | DROP FUNCTION IF EXISTS is_time(s VARCHAR); 51 | DROP FUNCTION IF EXISTS is_date(s VARCHAR, f VARCHAR); 52 | DROP FUNCTION IF EXISTS is_date(s VARCHAR); 53 | 54 | END; 55 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.1.1.sql: -------------------------------------------------------------------------------- 1 | SET client_min_messages TO warning; 2 | SET log_min_messages TO warning; 3 | 4 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 5 | 6 | BEGIN; 7 | 8 | DROP VIEW IF EXISTS pg_active_locks; 9 | DROP FUNCTION IF EXISTS is_empty(s VARCHAR); 10 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 11 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 12 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 17 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 18 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 19 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 20 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 21 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 22 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 23 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 24 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 25 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 26 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 27 | DROP FUNCTION IF EXISTS date_de(d DATE); 28 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 29 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 30 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 31 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, replacement VARCHAR); 32 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR); 33 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 34 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR, replacement VARCHAR); 35 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR); 36 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s VARCHAR, e VARCHAR); 37 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s VARCHAR); 38 | DROP FUNCTION IF EXISTS is_latin1(s VARCHAR); 39 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR, enc_from VARCHAR); 40 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR); 41 | DROP VIEW IF EXISTS pg_functions; 42 | DROP VIEW IF EXISTS pg_foreign_keys; 43 | DROP VIEW IF EXISTS pg_db_views; 44 | DROP FUNCTION IF EXISTS pg_schema_size(text); 45 | DROP FUNCTION IF EXISTS sha256(bytea); 46 | DROP FUNCTION IF EXISTS is_integer(s VARCHAR); 47 | DROP FUNCTION IF EXISTS is_numeric(s VARCHAR); 48 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR, f VARCHAR); 49 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR); 50 | DROP FUNCTION IF EXISTS is_time(s VARCHAR, f VARCHAR); 51 | DROP FUNCTION IF EXISTS is_time(s VARCHAR); 52 | DROP FUNCTION IF EXISTS is_date(s VARCHAR, f VARCHAR); 53 | DROP FUNCTION IF EXISTS is_date(s VARCHAR); 54 | 55 | END; 56 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.10.0.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s text); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS array_trim(a text[], rd BOOLEAN); 34 | DROP FUNCTION IF EXISTS array_trim(a SMALLINT[], rd BOOLEAN); 35 | DROP FUNCTION IF EXISTS array_trim(a INTEGER[], rd BOOLEAN); 36 | DROP FUNCTION IF EXISTS array_trim(a BIGINT[], rd BOOLEAN); 37 | DROP FUNCTION IF EXISTS array_trim(a NUMERIC[], rd BOOLEAN); 38 | DROP FUNCTION IF EXISTS array_trim(a REAL[], rd BOOLEAN); 39 | DROP FUNCTION IF EXISTS array_trim(a DOUBLE PRECISION[], rd BOOLEAN); 40 | DROP FUNCTION IF EXISTS array_trim(a DATE[], rd BOOLEAN); 41 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP[], rd BOOLEAN); 42 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP WITH TIME ZONE[], rd BOOLEAN); 43 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 44 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 45 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 46 | DROP FUNCTION IF EXISTS date_de(d DATE); 47 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 48 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 49 | DROP FUNCTION IF EXISTS replace_latin1(s text, s_search text[], s_replace text[]); 50 | DROP FUNCTION IF EXISTS replace_latin1(s text, replacement text); 51 | DROP FUNCTION IF EXISTS replace_latin1(s text); 52 | DROP FUNCTION IF EXISTS replace_encoding(s text, s_search text[], s_replace text[]); 53 | DROP FUNCTION IF EXISTS replace_encoding(s text, e text, replacement text); 54 | DROP FUNCTION IF EXISTS replace_encoding(s text, e text); 55 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s text, e text); 56 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s text); 57 | DROP FUNCTION IF EXISTS is_latin1(s text); 58 | DROP FUNCTION IF EXISTS is_encoding(s text, enc text, enc_from text); 59 | DROP FUNCTION IF EXISTS is_encoding(s text, enc text); 60 | DROP VIEW IF EXISTS pg_functions; 61 | DROP VIEW IF EXISTS pg_foreign_keys; 62 | DROP VIEW IF EXISTS pg_db_views; 63 | DROP VIEW IF EXISTS pg_table_matview_infos; 64 | DROP VIEW IF EXISTS pg_object_ownership; 65 | DROP VIEW IF EXISTS pg_bloat_info; 66 | DROP VIEW IF EXISTS pg_unused_indexes; 67 | DROP VIEW IF EXISTS pg_partitioned_tables_infos; 68 | DROP FUNCTION IF EXISTS pg_schema_size(text); 69 | DROP FUNCTION IF EXISTS sha256(bytea); 70 | DROP FUNCTION IF EXISTS is_bigint(s text); 71 | DROP FUNCTION IF EXISTS is_integer(s text); 72 | DROP FUNCTION IF EXISTS is_smallint(s text); 73 | DROP FUNCTION IF EXISTS is_numeric(s text); 74 | DROP FUNCTION IF EXISTS is_real(s text); 75 | DROP FUNCTION IF EXISTS is_double_precision(s text); 76 | DROP FUNCTION IF EXISTS is_boolean(s text); 77 | DROP FUNCTION IF EXISTS is_json(s text); 78 | DROP FUNCTION IF EXISTS is_timestamp(s text, f text); 79 | DROP FUNCTION IF EXISTS is_timestamp(s text); 80 | DROP FUNCTION IF EXISTS is_time(s text, f text); 81 | DROP FUNCTION IF EXISTS is_time(s text); 82 | DROP FUNCTION IF EXISTS is_date(s text, f text); 83 | DROP FUNCTION IF EXISTS is_json(s text); 84 | DROP FUNCTION IF EXISTS is_jsonb(s text); 85 | DROP FUNCTION IF EXISTS is_hex(s TEXT); 86 | DROP FUNCTION IF EXISTS is_uuid(s TEXT); 87 | DROP FUNCTION IF EXISTS hex2bigint(s TEXT); 88 | DROP FUNCTION IF EXISTS is_bigint_array(s TEXT); 89 | DROP FUNCTION IF EXISTS is_integer_array(s TEXT); 90 | DROP FUNCTION IF EXISTS is_smallint_array(s TEXT); 91 | DROP FUNCTION IF EXISTS is_text_array(s TEXT); 92 | 93 | END; 94 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.10.1.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s text); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS array_trim(a text[], rd BOOLEAN); 34 | DROP FUNCTION IF EXISTS array_trim(a SMALLINT[], rd BOOLEAN); 35 | DROP FUNCTION IF EXISTS array_trim(a INTEGER[], rd BOOLEAN); 36 | DROP FUNCTION IF EXISTS array_trim(a BIGINT[], rd BOOLEAN); 37 | DROP FUNCTION IF EXISTS array_trim(a NUMERIC[], rd BOOLEAN); 38 | DROP FUNCTION IF EXISTS array_trim(a REAL[], rd BOOLEAN); 39 | DROP FUNCTION IF EXISTS array_trim(a DOUBLE PRECISION[], rd BOOLEAN); 40 | DROP FUNCTION IF EXISTS array_trim(a DATE[], rd BOOLEAN); 41 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP[], rd BOOLEAN); 42 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP WITH TIME ZONE[], rd BOOLEAN); 43 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 44 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 45 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 46 | DROP FUNCTION IF EXISTS date_de(d DATE); 47 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 48 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 49 | DROP FUNCTION IF EXISTS replace_latin1(s text, s_search text[], s_replace text[]); 50 | DROP FUNCTION IF EXISTS replace_latin1(s text, replacement text); 51 | DROP FUNCTION IF EXISTS replace_latin1(s text); 52 | DROP FUNCTION IF EXISTS replace_encoding(s text, s_search text[], s_replace text[]); 53 | DROP FUNCTION IF EXISTS replace_encoding(s text, e text, replacement text); 54 | DROP FUNCTION IF EXISTS replace_encoding(s text, e text); 55 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s text, e text); 56 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s text); 57 | DROP FUNCTION IF EXISTS is_latin1(s text); 58 | DROP FUNCTION IF EXISTS is_encoding(s text, enc text, enc_from text); 59 | DROP FUNCTION IF EXISTS is_encoding(s text, enc text); 60 | DROP VIEW IF EXISTS pg_functions; 61 | DROP VIEW IF EXISTS pg_foreign_keys; 62 | DROP VIEW IF EXISTS pg_db_views; 63 | DROP VIEW IF EXISTS pg_table_matview_infos; 64 | DROP VIEW IF EXISTS pg_object_ownership; 65 | DROP VIEW IF EXISTS pg_bloat_info; 66 | DROP VIEW IF EXISTS pg_unused_indexes; 67 | DROP VIEW IF EXISTS pg_partitioned_tables_infos; 68 | DROP FUNCTION IF EXISTS pg_schema_size(text); 69 | DROP FUNCTION IF EXISTS sha256(bytea); 70 | DROP FUNCTION IF EXISTS is_bigint(s text); 71 | DROP FUNCTION IF EXISTS is_integer(s text); 72 | DROP FUNCTION IF EXISTS is_smallint(s text); 73 | DROP FUNCTION IF EXISTS is_numeric(s text); 74 | DROP FUNCTION IF EXISTS is_real(s text); 75 | DROP FUNCTION IF EXISTS is_double_precision(s text); 76 | DROP FUNCTION IF EXISTS is_boolean(s text); 77 | DROP FUNCTION IF EXISTS is_json(s text); 78 | DROP FUNCTION IF EXISTS is_timestamp(s text, f text); 79 | DROP FUNCTION IF EXISTS is_timestamp(s text); 80 | DROP FUNCTION IF EXISTS is_time(s text, f text); 81 | DROP FUNCTION IF EXISTS is_time(s text); 82 | DROP FUNCTION IF EXISTS is_date(s text, f text); 83 | DROP FUNCTION IF EXISTS is_json(s text); 84 | DROP FUNCTION IF EXISTS is_jsonb(s text); 85 | DROP FUNCTION IF EXISTS is_hex(s TEXT); 86 | DROP FUNCTION IF EXISTS is_uuid(s TEXT); 87 | DROP FUNCTION IF EXISTS hex2bigint(s TEXT); 88 | DROP FUNCTION IF EXISTS is_bigint_array(s TEXT); 89 | DROP FUNCTION IF EXISTS is_integer_array(s TEXT); 90 | DROP FUNCTION IF EXISTS is_smallint_array(s TEXT); 91 | DROP FUNCTION IF EXISTS is_text_array(s TEXT); 92 | 93 | END; 94 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.2.0.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s VARCHAR); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 34 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 35 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 36 | DROP FUNCTION IF EXISTS date_de(d DATE); 37 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 38 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 39 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 40 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, replacement VARCHAR); 41 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR); 42 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 43 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR, replacement VARCHAR); 44 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR); 45 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s VARCHAR, e VARCHAR); 46 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s VARCHAR); 47 | DROP FUNCTION IF EXISTS is_latin1(s VARCHAR); 48 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR, enc_from VARCHAR); 49 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR); 50 | DROP VIEW IF EXISTS pg_functions; 51 | DROP VIEW IF EXISTS pg_foreign_keys; 52 | DROP VIEW IF EXISTS pg_db_views; 53 | DROP FUNCTION IF EXISTS pg_schema_size(text); 54 | DROP FUNCTION IF EXISTS sha256(bytea); 55 | DROP FUNCTION IF EXISTS is_bigint(s VARCHAR); 56 | DROP FUNCTION IF EXISTS is_integer(s VARCHAR); 57 | DROP FUNCTION IF EXISTS is_smallint(s VARCHAR); 58 | DROP FUNCTION IF EXISTS is_numeric(s VARCHAR); 59 | DROP FUNCTION IF EXISTS is_real(s VARCHAR); 60 | DROP FUNCTION IF EXISTS is_double_precision(s VARCHAR); 61 | DROP FUNCTION IF EXISTS is_boolean(s VARCHAR); 62 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR, f VARCHAR); 63 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR); 64 | DROP FUNCTION IF EXISTS is_time(s VARCHAR, f VARCHAR); 65 | DROP FUNCTION IF EXISTS is_time(s VARCHAR); 66 | DROP FUNCTION IF EXISTS is_date(s VARCHAR, f VARCHAR); 67 | DROP FUNCTION IF EXISTS is_date(s VARCHAR); 68 | 69 | END; 70 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.2.1.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s VARCHAR); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 34 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 35 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 36 | DROP FUNCTION IF EXISTS date_de(d DATE); 37 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 38 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 39 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 40 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, replacement VARCHAR); 41 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR); 42 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 43 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR, replacement VARCHAR); 44 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR); 45 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s VARCHAR, e VARCHAR); 46 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s VARCHAR); 47 | DROP FUNCTION IF EXISTS is_latin1(s VARCHAR); 48 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR, enc_from VARCHAR); 49 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR); 50 | DROP VIEW IF EXISTS pg_functions; 51 | DROP VIEW IF EXISTS pg_foreign_keys; 52 | DROP VIEW IF EXISTS pg_db_views; 53 | DROP FUNCTION IF EXISTS pg_schema_size(text); 54 | DROP FUNCTION IF EXISTS sha256(bytea); 55 | DROP FUNCTION IF EXISTS is_bigint(s VARCHAR); 56 | DROP FUNCTION IF EXISTS is_integer(s VARCHAR); 57 | DROP FUNCTION IF EXISTS is_smallint(s VARCHAR); 58 | DROP FUNCTION IF EXISTS is_numeric(s VARCHAR); 59 | DROP FUNCTION IF EXISTS is_real(s VARCHAR); 60 | DROP FUNCTION IF EXISTS is_double_precision(s VARCHAR); 61 | DROP FUNCTION IF EXISTS is_boolean(s VARCHAR); 62 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR, f VARCHAR); 63 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR); 64 | DROP FUNCTION IF EXISTS is_time(s VARCHAR, f VARCHAR); 65 | DROP FUNCTION IF EXISTS is_time(s VARCHAR); 66 | DROP FUNCTION IF EXISTS is_date(s VARCHAR, f VARCHAR); 67 | DROP FUNCTION IF EXISTS is_date(s VARCHAR); 68 | 69 | END; 70 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.2.2.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s VARCHAR); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 34 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 35 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 36 | DROP FUNCTION IF EXISTS date_de(d DATE); 37 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 38 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 39 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 40 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, replacement VARCHAR); 41 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR); 42 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 43 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR, replacement VARCHAR); 44 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR); 45 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s VARCHAR, e VARCHAR); 46 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s VARCHAR); 47 | DROP FUNCTION IF EXISTS is_latin1(s VARCHAR); 48 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR, enc_from VARCHAR); 49 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR); 50 | DROP VIEW IF EXISTS pg_functions; 51 | DROP VIEW IF EXISTS pg_foreign_keys; 52 | DROP VIEW IF EXISTS pg_db_views; 53 | DROP FUNCTION IF EXISTS pg_schema_size(text); 54 | DROP FUNCTION IF EXISTS sha256(bytea); 55 | DROP FUNCTION IF EXISTS is_bigint(s VARCHAR); 56 | DROP FUNCTION IF EXISTS is_integer(s VARCHAR); 57 | DROP FUNCTION IF EXISTS is_smallint(s VARCHAR); 58 | DROP FUNCTION IF EXISTS is_numeric(s VARCHAR); 59 | DROP FUNCTION IF EXISTS is_real(s VARCHAR); 60 | DROP FUNCTION IF EXISTS is_double_precision(s VARCHAR); 61 | DROP FUNCTION IF EXISTS is_boolean(s VARCHAR); 62 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR, f VARCHAR); 63 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR); 64 | DROP FUNCTION IF EXISTS is_time(s VARCHAR, f VARCHAR); 65 | DROP FUNCTION IF EXISTS is_time(s VARCHAR); 66 | DROP FUNCTION IF EXISTS is_date(s VARCHAR, f VARCHAR); 67 | DROP FUNCTION IF EXISTS is_date(s VARCHAR); 68 | 69 | END; 70 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.2.3.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s VARCHAR); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 34 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 35 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 36 | DROP FUNCTION IF EXISTS date_de(d DATE); 37 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 38 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 39 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 40 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, replacement VARCHAR); 41 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR); 42 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 43 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR, replacement VARCHAR); 44 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR); 45 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s VARCHAR, e VARCHAR); 46 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s VARCHAR); 47 | DROP FUNCTION IF EXISTS is_latin1(s VARCHAR); 48 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR, enc_from VARCHAR); 49 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR); 50 | DROP VIEW IF EXISTS pg_functions; 51 | DROP VIEW IF EXISTS pg_foreign_keys; 52 | DROP VIEW IF EXISTS pg_db_views; 53 | DROP FUNCTION IF EXISTS pg_schema_size(text); 54 | DROP FUNCTION IF EXISTS sha256(bytea); 55 | DROP FUNCTION IF EXISTS is_bigint(s VARCHAR); 56 | DROP FUNCTION IF EXISTS is_integer(s VARCHAR); 57 | DROP FUNCTION IF EXISTS is_smallint(s VARCHAR); 58 | DROP FUNCTION IF EXISTS is_numeric(s VARCHAR); 59 | DROP FUNCTION IF EXISTS is_real(s VARCHAR); 60 | DROP FUNCTION IF EXISTS is_double_precision(s VARCHAR); 61 | DROP FUNCTION IF EXISTS is_boolean(s VARCHAR); 62 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR, f VARCHAR); 63 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR); 64 | DROP FUNCTION IF EXISTS is_time(s VARCHAR, f VARCHAR); 65 | DROP FUNCTION IF EXISTS is_time(s VARCHAR); 66 | DROP FUNCTION IF EXISTS is_date(s VARCHAR, f VARCHAR); 67 | DROP FUNCTION IF EXISTS is_date(s VARCHAR); 68 | 69 | END; 70 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.2.4.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s VARCHAR); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 34 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 35 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 36 | DROP FUNCTION IF EXISTS date_de(d DATE); 37 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 38 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 39 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 40 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, replacement VARCHAR); 41 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR); 42 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 43 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR, replacement VARCHAR); 44 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR); 45 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s VARCHAR, e VARCHAR); 46 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s VARCHAR); 47 | DROP FUNCTION IF EXISTS is_latin1(s VARCHAR); 48 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR, enc_from VARCHAR); 49 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR); 50 | DROP VIEW IF EXISTS pg_functions; 51 | DROP VIEW IF EXISTS pg_foreign_keys; 52 | DROP VIEW IF EXISTS pg_db_views; 53 | DROP FUNCTION IF EXISTS pg_schema_size(text); 54 | DROP FUNCTION IF EXISTS sha256(bytea); 55 | DROP FUNCTION IF EXISTS is_bigint(s VARCHAR); 56 | DROP FUNCTION IF EXISTS is_integer(s VARCHAR); 57 | DROP FUNCTION IF EXISTS is_smallint(s VARCHAR); 58 | DROP FUNCTION IF EXISTS is_numeric(s VARCHAR); 59 | DROP FUNCTION IF EXISTS is_real(s VARCHAR); 60 | DROP FUNCTION IF EXISTS is_double_precision(s VARCHAR); 61 | DROP FUNCTION IF EXISTS is_boolean(s VARCHAR); 62 | DROP FUNCTION IF EXISTS is_json(s VARCHAR); 63 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR, f VARCHAR); 64 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR); 65 | DROP FUNCTION IF EXISTS is_time(s VARCHAR, f VARCHAR); 66 | DROP FUNCTION IF EXISTS is_time(s VARCHAR); 67 | DROP FUNCTION IF EXISTS is_date(s VARCHAR, f VARCHAR); 68 | DROP FUNCTION IF EXISTS is_date(s VARCHAR); 69 | 70 | END; 71 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.2.5.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s VARCHAR); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 34 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 35 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 36 | DROP FUNCTION IF EXISTS date_de(d DATE); 37 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 38 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 39 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 40 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, replacement VARCHAR); 41 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR); 42 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 43 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR, replacement VARCHAR); 44 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR); 45 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s VARCHAR, e VARCHAR); 46 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s VARCHAR); 47 | DROP FUNCTION IF EXISTS is_latin1(s VARCHAR); 48 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR, enc_from VARCHAR); 49 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR); 50 | DROP VIEW IF EXISTS pg_functions; 51 | DROP VIEW IF EXISTS pg_foreign_keys; 52 | DROP VIEW IF EXISTS pg_db_views; 53 | DROP FUNCTION IF EXISTS pg_schema_size(text); 54 | DROP FUNCTION IF EXISTS sha256(bytea); 55 | DROP FUNCTION IF EXISTS is_bigint(s VARCHAR); 56 | DROP FUNCTION IF EXISTS is_integer(s VARCHAR); 57 | DROP FUNCTION IF EXISTS is_smallint(s VARCHAR); 58 | DROP FUNCTION IF EXISTS is_numeric(s VARCHAR); 59 | DROP FUNCTION IF EXISTS is_real(s VARCHAR); 60 | DROP FUNCTION IF EXISTS is_double_precision(s VARCHAR); 61 | DROP FUNCTION IF EXISTS is_boolean(s VARCHAR); 62 | DROP FUNCTION IF EXISTS is_json(s VARCHAR); 63 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR, f VARCHAR); 64 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR); 65 | DROP FUNCTION IF EXISTS is_time(s VARCHAR, f VARCHAR); 66 | DROP FUNCTION IF EXISTS is_time(s VARCHAR); 67 | DROP FUNCTION IF EXISTS is_date(s VARCHAR, f VARCHAR); 68 | DROP FUNCTION IF EXISTS is_json(s VARCHAR); 69 | DROP FUNCTION IF EXISTS is_jsonb(s VARCHAR); 70 | 71 | END; 72 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.3.0.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s VARCHAR); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS array_trim(a VARCHAR[], rd BOOLEAN); 34 | DROP FUNCTION IF EXISTS array_trim(a SMALLINT[], rd BOOLEAN); 35 | DROP FUNCTION IF EXISTS array_trim(a INTEGER[], rd BOOLEAN); 36 | DROP FUNCTION IF EXISTS array_trim(a BIGINT[], rd BOOLEAN); 37 | DROP FUNCTION IF EXISTS array_trim(a NUMERIC[], rd BOOLEAN); 38 | DROP FUNCTION IF EXISTS array_trim(a REAL[], rd BOOLEAN); 39 | DROP FUNCTION IF EXISTS array_trim(a DOUBLE PRECISION[], rd BOOLEAN); 40 | DROP FUNCTION IF EXISTS array_trim(a DATE[], rd BOOLEAN); 41 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP[], rd BOOLEAN); 42 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP WITH TIME ZONE[], rd BOOLEAN); 43 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 44 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 45 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 46 | DROP FUNCTION IF EXISTS date_de(d DATE); 47 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 48 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 49 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 50 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, replacement VARCHAR); 51 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR); 52 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 53 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR, replacement VARCHAR); 54 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR); 55 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s VARCHAR, e VARCHAR); 56 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s VARCHAR); 57 | DROP FUNCTION IF EXISTS is_latin1(s VARCHAR); 58 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR, enc_from VARCHAR); 59 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR); 60 | DROP VIEW IF EXISTS pg_functions; 61 | DROP VIEW IF EXISTS pg_foreign_keys; 62 | DROP VIEW IF EXISTS pg_db_views; 63 | DROP VIEW IF EXISTS pg_table_matview_infos; 64 | DROP FUNCTION IF EXISTS pg_schema_size(text); 65 | DROP FUNCTION IF EXISTS sha256(bytea); 66 | DROP FUNCTION IF EXISTS is_bigint(s VARCHAR); 67 | DROP FUNCTION IF EXISTS is_integer(s VARCHAR); 68 | DROP FUNCTION IF EXISTS is_smallint(s VARCHAR); 69 | DROP FUNCTION IF EXISTS is_numeric(s VARCHAR); 70 | DROP FUNCTION IF EXISTS is_real(s VARCHAR); 71 | DROP FUNCTION IF EXISTS is_double_precision(s VARCHAR); 72 | DROP FUNCTION IF EXISTS is_boolean(s VARCHAR); 73 | DROP FUNCTION IF EXISTS is_json(s VARCHAR); 74 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR, f VARCHAR); 75 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR); 76 | DROP FUNCTION IF EXISTS is_time(s VARCHAR, f VARCHAR); 77 | DROP FUNCTION IF EXISTS is_time(s VARCHAR); 78 | DROP FUNCTION IF EXISTS is_date(s VARCHAR, f VARCHAR); 79 | DROP FUNCTION IF EXISTS is_json(s VARCHAR); 80 | DROP FUNCTION IF EXISTS is_jsonb(s VARCHAR); 81 | 82 | END; 83 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.3.1.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s VARCHAR); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS array_trim(a VARCHAR[], rd BOOLEAN); 34 | DROP FUNCTION IF EXISTS array_trim(a SMALLINT[], rd BOOLEAN); 35 | DROP FUNCTION IF EXISTS array_trim(a INTEGER[], rd BOOLEAN); 36 | DROP FUNCTION IF EXISTS array_trim(a BIGINT[], rd BOOLEAN); 37 | DROP FUNCTION IF EXISTS array_trim(a NUMERIC[], rd BOOLEAN); 38 | DROP FUNCTION IF EXISTS array_trim(a REAL[], rd BOOLEAN); 39 | DROP FUNCTION IF EXISTS array_trim(a DOUBLE PRECISION[], rd BOOLEAN); 40 | DROP FUNCTION IF EXISTS array_trim(a DATE[], rd BOOLEAN); 41 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP[], rd BOOLEAN); 42 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP WITH TIME ZONE[], rd BOOLEAN); 43 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 44 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 45 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 46 | DROP FUNCTION IF EXISTS date_de(d DATE); 47 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 48 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 49 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 50 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, replacement VARCHAR); 51 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR); 52 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 53 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR, replacement VARCHAR); 54 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR); 55 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s VARCHAR, e VARCHAR); 56 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s VARCHAR); 57 | DROP FUNCTION IF EXISTS is_latin1(s VARCHAR); 58 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR, enc_from VARCHAR); 59 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR); 60 | DROP VIEW IF EXISTS pg_functions; 61 | DROP VIEW IF EXISTS pg_foreign_keys; 62 | DROP VIEW IF EXISTS pg_db_views; 63 | DROP VIEW IF EXISTS pg_table_matview_infos; 64 | DROP FUNCTION IF EXISTS pg_schema_size(text); 65 | DROP FUNCTION IF EXISTS sha256(bytea); 66 | DROP FUNCTION IF EXISTS is_bigint(s VARCHAR); 67 | DROP FUNCTION IF EXISTS is_integer(s VARCHAR); 68 | DROP FUNCTION IF EXISTS is_smallint(s VARCHAR); 69 | DROP FUNCTION IF EXISTS is_numeric(s VARCHAR); 70 | DROP FUNCTION IF EXISTS is_real(s VARCHAR); 71 | DROP FUNCTION IF EXISTS is_double_precision(s VARCHAR); 72 | DROP FUNCTION IF EXISTS is_boolean(s VARCHAR); 73 | DROP FUNCTION IF EXISTS is_json(s VARCHAR); 74 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR, f VARCHAR); 75 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR); 76 | DROP FUNCTION IF EXISTS is_time(s VARCHAR, f VARCHAR); 77 | DROP FUNCTION IF EXISTS is_time(s VARCHAR); 78 | DROP FUNCTION IF EXISTS is_date(s VARCHAR, f VARCHAR); 79 | DROP FUNCTION IF EXISTS is_json(s VARCHAR); 80 | DROP FUNCTION IF EXISTS is_jsonb(s VARCHAR); 81 | 82 | END; 83 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.4.0.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s VARCHAR); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS array_trim(a VARCHAR[], rd BOOLEAN); 34 | DROP FUNCTION IF EXISTS array_trim(a SMALLINT[], rd BOOLEAN); 35 | DROP FUNCTION IF EXISTS array_trim(a INTEGER[], rd BOOLEAN); 36 | DROP FUNCTION IF EXISTS array_trim(a BIGINT[], rd BOOLEAN); 37 | DROP FUNCTION IF EXISTS array_trim(a NUMERIC[], rd BOOLEAN); 38 | DROP FUNCTION IF EXISTS array_trim(a REAL[], rd BOOLEAN); 39 | DROP FUNCTION IF EXISTS array_trim(a DOUBLE PRECISION[], rd BOOLEAN); 40 | DROP FUNCTION IF EXISTS array_trim(a DATE[], rd BOOLEAN); 41 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP[], rd BOOLEAN); 42 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP WITH TIME ZONE[], rd BOOLEAN); 43 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 44 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 45 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 46 | DROP FUNCTION IF EXISTS date_de(d DATE); 47 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 48 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 49 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 50 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, replacement VARCHAR); 51 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR); 52 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 53 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR, replacement VARCHAR); 54 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR); 55 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s VARCHAR, e VARCHAR); 56 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s VARCHAR); 57 | DROP FUNCTION IF EXISTS is_latin1(s VARCHAR); 58 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR, enc_from VARCHAR); 59 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR); 60 | DROP VIEW IF EXISTS pg_functions; 61 | DROP VIEW IF EXISTS pg_foreign_keys; 62 | DROP VIEW IF EXISTS pg_db_views; 63 | DROP VIEW IF EXISTS pg_table_matview_infos; 64 | DROP FUNCTION IF EXISTS pg_schema_size(text); 65 | DROP FUNCTION IF EXISTS sha256(bytea); 66 | DROP FUNCTION IF EXISTS is_bigint(s VARCHAR); 67 | DROP FUNCTION IF EXISTS is_integer(s VARCHAR); 68 | DROP FUNCTION IF EXISTS is_smallint(s VARCHAR); 69 | DROP FUNCTION IF EXISTS is_numeric(s VARCHAR); 70 | DROP FUNCTION IF EXISTS is_real(s VARCHAR); 71 | DROP FUNCTION IF EXISTS is_double_precision(s VARCHAR); 72 | DROP FUNCTION IF EXISTS is_boolean(s VARCHAR); 73 | DROP FUNCTION IF EXISTS is_json(s VARCHAR); 74 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR, f VARCHAR); 75 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR); 76 | DROP FUNCTION IF EXISTS is_time(s VARCHAR, f VARCHAR); 77 | DROP FUNCTION IF EXISTS is_time(s VARCHAR); 78 | DROP FUNCTION IF EXISTS is_date(s VARCHAR, f VARCHAR); 79 | DROP FUNCTION IF EXISTS is_json(s VARCHAR); 80 | DROP FUNCTION IF EXISTS is_jsonb(s VARCHAR); 81 | 82 | END; 83 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.4.1.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s VARCHAR); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS array_trim(a VARCHAR[], rd BOOLEAN); 34 | DROP FUNCTION IF EXISTS array_trim(a SMALLINT[], rd BOOLEAN); 35 | DROP FUNCTION IF EXISTS array_trim(a INTEGER[], rd BOOLEAN); 36 | DROP FUNCTION IF EXISTS array_trim(a BIGINT[], rd BOOLEAN); 37 | DROP FUNCTION IF EXISTS array_trim(a NUMERIC[], rd BOOLEAN); 38 | DROP FUNCTION IF EXISTS array_trim(a REAL[], rd BOOLEAN); 39 | DROP FUNCTION IF EXISTS array_trim(a DOUBLE PRECISION[], rd BOOLEAN); 40 | DROP FUNCTION IF EXISTS array_trim(a DATE[], rd BOOLEAN); 41 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP[], rd BOOLEAN); 42 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP WITH TIME ZONE[], rd BOOLEAN); 43 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 44 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 45 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 46 | DROP FUNCTION IF EXISTS date_de(d DATE); 47 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 48 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 49 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 50 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, replacement VARCHAR); 51 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR); 52 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 53 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR, replacement VARCHAR); 54 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR); 55 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s VARCHAR, e VARCHAR); 56 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s VARCHAR); 57 | DROP FUNCTION IF EXISTS is_latin1(s VARCHAR); 58 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR, enc_from VARCHAR); 59 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR); 60 | DROP VIEW IF EXISTS pg_functions; 61 | DROP VIEW IF EXISTS pg_foreign_keys; 62 | DROP VIEW IF EXISTS pg_db_views; 63 | DROP VIEW IF EXISTS pg_table_matview_infos; 64 | DROP FUNCTION IF EXISTS pg_schema_size(text); 65 | DROP FUNCTION IF EXISTS sha256(bytea); 66 | DROP FUNCTION IF EXISTS is_bigint(s VARCHAR); 67 | DROP FUNCTION IF EXISTS is_integer(s VARCHAR); 68 | DROP FUNCTION IF EXISTS is_smallint(s VARCHAR); 69 | DROP FUNCTION IF EXISTS is_numeric(s VARCHAR); 70 | DROP FUNCTION IF EXISTS is_real(s VARCHAR); 71 | DROP FUNCTION IF EXISTS is_double_precision(s VARCHAR); 72 | DROP FUNCTION IF EXISTS is_boolean(s VARCHAR); 73 | DROP FUNCTION IF EXISTS is_json(s VARCHAR); 74 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR, f VARCHAR); 75 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR); 76 | DROP FUNCTION IF EXISTS is_time(s VARCHAR, f VARCHAR); 77 | DROP FUNCTION IF EXISTS is_time(s VARCHAR); 78 | DROP FUNCTION IF EXISTS is_date(s VARCHAR, f VARCHAR); 79 | DROP FUNCTION IF EXISTS is_json(s VARCHAR); 80 | DROP FUNCTION IF EXISTS is_jsonb(s VARCHAR); 81 | 82 | END; 83 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.4.2.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s VARCHAR); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS array_trim(a VARCHAR[], rd BOOLEAN); 34 | DROP FUNCTION IF EXISTS array_trim(a SMALLINT[], rd BOOLEAN); 35 | DROP FUNCTION IF EXISTS array_trim(a INTEGER[], rd BOOLEAN); 36 | DROP FUNCTION IF EXISTS array_trim(a BIGINT[], rd BOOLEAN); 37 | DROP FUNCTION IF EXISTS array_trim(a NUMERIC[], rd BOOLEAN); 38 | DROP FUNCTION IF EXISTS array_trim(a REAL[], rd BOOLEAN); 39 | DROP FUNCTION IF EXISTS array_trim(a DOUBLE PRECISION[], rd BOOLEAN); 40 | DROP FUNCTION IF EXISTS array_trim(a DATE[], rd BOOLEAN); 41 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP[], rd BOOLEAN); 42 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP WITH TIME ZONE[], rd BOOLEAN); 43 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 44 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 45 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 46 | DROP FUNCTION IF EXISTS date_de(d DATE); 47 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 48 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 49 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 50 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, replacement VARCHAR); 51 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR); 52 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 53 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR, replacement VARCHAR); 54 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR); 55 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s VARCHAR, e VARCHAR); 56 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s VARCHAR); 57 | DROP FUNCTION IF EXISTS is_latin1(s VARCHAR); 58 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR, enc_from VARCHAR); 59 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR); 60 | DROP VIEW IF EXISTS pg_functions; 61 | DROP VIEW IF EXISTS pg_foreign_keys; 62 | DROP VIEW IF EXISTS pg_db_views; 63 | DROP VIEW IF EXISTS pg_table_matview_infos; 64 | DROP FUNCTION IF EXISTS pg_schema_size(text); 65 | DROP FUNCTION IF EXISTS sha256(bytea); 66 | DROP FUNCTION IF EXISTS is_bigint(s VARCHAR); 67 | DROP FUNCTION IF EXISTS is_integer(s VARCHAR); 68 | DROP FUNCTION IF EXISTS is_smallint(s VARCHAR); 69 | DROP FUNCTION IF EXISTS is_numeric(s VARCHAR); 70 | DROP FUNCTION IF EXISTS is_real(s VARCHAR); 71 | DROP FUNCTION IF EXISTS is_double_precision(s VARCHAR); 72 | DROP FUNCTION IF EXISTS is_boolean(s VARCHAR); 73 | DROP FUNCTION IF EXISTS is_json(s VARCHAR); 74 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR, f VARCHAR); 75 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR); 76 | DROP FUNCTION IF EXISTS is_time(s VARCHAR, f VARCHAR); 77 | DROP FUNCTION IF EXISTS is_time(s VARCHAR); 78 | DROP FUNCTION IF EXISTS is_date(s VARCHAR, f VARCHAR); 79 | DROP FUNCTION IF EXISTS is_json(s VARCHAR); 80 | DROP FUNCTION IF EXISTS is_jsonb(s VARCHAR); 81 | 82 | END; 83 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.5.0.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s VARCHAR); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS array_trim(a VARCHAR[], rd BOOLEAN); 34 | DROP FUNCTION IF EXISTS array_trim(a SMALLINT[], rd BOOLEAN); 35 | DROP FUNCTION IF EXISTS array_trim(a INTEGER[], rd BOOLEAN); 36 | DROP FUNCTION IF EXISTS array_trim(a BIGINT[], rd BOOLEAN); 37 | DROP FUNCTION IF EXISTS array_trim(a NUMERIC[], rd BOOLEAN); 38 | DROP FUNCTION IF EXISTS array_trim(a REAL[], rd BOOLEAN); 39 | DROP FUNCTION IF EXISTS array_trim(a DOUBLE PRECISION[], rd BOOLEAN); 40 | DROP FUNCTION IF EXISTS array_trim(a DATE[], rd BOOLEAN); 41 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP[], rd BOOLEAN); 42 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP WITH TIME ZONE[], rd BOOLEAN); 43 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 44 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 45 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 46 | DROP FUNCTION IF EXISTS date_de(d DATE); 47 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 48 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 49 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 50 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR, replacement VARCHAR); 51 | DROP FUNCTION IF EXISTS replace_latin1(s VARCHAR); 52 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, s_search VARCHAR[], s_replace VARCHAR[]); 53 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR, replacement VARCHAR); 54 | DROP FUNCTION IF EXISTS replace_encoding(s VARCHAR, e VARCHAR); 55 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s VARCHAR, e VARCHAR); 56 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s VARCHAR); 57 | DROP FUNCTION IF EXISTS is_latin1(s VARCHAR); 58 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR, enc_from VARCHAR); 59 | DROP FUNCTION IF EXISTS is_encoding(s VARCHAR, enc VARCHAR); 60 | DROP VIEW IF EXISTS pg_functions; 61 | DROP VIEW IF EXISTS pg_foreign_keys; 62 | DROP VIEW IF EXISTS pg_db_views; 63 | DROP VIEW IF EXISTS pg_table_matview_infos; 64 | DROP VIEW IF EXISTS pg_object_ownership; 65 | DROP FUNCTION IF EXISTS pg_schema_size(text); 66 | DROP FUNCTION IF EXISTS sha256(bytea); 67 | DROP FUNCTION IF EXISTS is_bigint(s VARCHAR); 68 | DROP FUNCTION IF EXISTS is_integer(s VARCHAR); 69 | DROP FUNCTION IF EXISTS is_smallint(s VARCHAR); 70 | DROP FUNCTION IF EXISTS is_numeric(s VARCHAR); 71 | DROP FUNCTION IF EXISTS is_real(s VARCHAR); 72 | DROP FUNCTION IF EXISTS is_double_precision(s VARCHAR); 73 | DROP FUNCTION IF EXISTS is_boolean(s VARCHAR); 74 | DROP FUNCTION IF EXISTS is_json(s VARCHAR); 75 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR, f VARCHAR); 76 | DROP FUNCTION IF EXISTS is_timestamp(s VARCHAR); 77 | DROP FUNCTION IF EXISTS is_time(s VARCHAR, f VARCHAR); 78 | DROP FUNCTION IF EXISTS is_time(s VARCHAR); 79 | DROP FUNCTION IF EXISTS is_date(s VARCHAR, f VARCHAR); 80 | DROP FUNCTION IF EXISTS is_json(s VARCHAR); 81 | DROP FUNCTION IF EXISTS is_jsonb(s VARCHAR); 82 | 83 | END; 84 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.6.0.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s text); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS array_trim(a text[], rd BOOLEAN); 34 | DROP FUNCTION IF EXISTS array_trim(a SMALLINT[], rd BOOLEAN); 35 | DROP FUNCTION IF EXISTS array_trim(a INTEGER[], rd BOOLEAN); 36 | DROP FUNCTION IF EXISTS array_trim(a BIGINT[], rd BOOLEAN); 37 | DROP FUNCTION IF EXISTS array_trim(a NUMERIC[], rd BOOLEAN); 38 | DROP FUNCTION IF EXISTS array_trim(a REAL[], rd BOOLEAN); 39 | DROP FUNCTION IF EXISTS array_trim(a DOUBLE PRECISION[], rd BOOLEAN); 40 | DROP FUNCTION IF EXISTS array_trim(a DATE[], rd BOOLEAN); 41 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP[], rd BOOLEAN); 42 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP WITH TIME ZONE[], rd BOOLEAN); 43 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 44 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 45 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 46 | DROP FUNCTION IF EXISTS date_de(d DATE); 47 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 48 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 49 | DROP FUNCTION IF EXISTS replace_latin1(s text, s_search text[], s_replace text[]); 50 | DROP FUNCTION IF EXISTS replace_latin1(s text, replacement text); 51 | DROP FUNCTION IF EXISTS replace_latin1(s text); 52 | DROP FUNCTION IF EXISTS replace_encoding(s text, s_search text[], s_replace text[]); 53 | DROP FUNCTION IF EXISTS replace_encoding(s text, e text, replacement text); 54 | DROP FUNCTION IF EXISTS replace_encoding(s text, e text); 55 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s text, e text); 56 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s text); 57 | DROP FUNCTION IF EXISTS is_latin1(s text); 58 | DROP FUNCTION IF EXISTS is_encoding(s text, enc text, enc_from text); 59 | DROP FUNCTION IF EXISTS is_encoding(s text, enc text); 60 | DROP VIEW IF EXISTS pg_functions; 61 | DROP VIEW IF EXISTS pg_foreign_keys; 62 | DROP VIEW IF EXISTS pg_db_views; 63 | DROP VIEW IF EXISTS pg_table_matview_infos; 64 | DROP VIEW IF EXISTS pg_object_ownership; 65 | DROP FUNCTION IF EXISTS pg_schema_size(text); 66 | DROP FUNCTION IF EXISTS sha256(bytea); 67 | DROP FUNCTION IF EXISTS is_bigint(s text); 68 | DROP FUNCTION IF EXISTS is_integer(s text); 69 | DROP FUNCTION IF EXISTS is_smallint(s text); 70 | DROP FUNCTION IF EXISTS is_numeric(s text); 71 | DROP FUNCTION IF EXISTS is_real(s text); 72 | DROP FUNCTION IF EXISTS is_double_precision(s text); 73 | DROP FUNCTION IF EXISTS is_boolean(s text); 74 | DROP FUNCTION IF EXISTS is_json(s text); 75 | DROP FUNCTION IF EXISTS is_timestamp(s text, f text); 76 | DROP FUNCTION IF EXISTS is_timestamp(s text); 77 | DROP FUNCTION IF EXISTS is_time(s text, f text); 78 | DROP FUNCTION IF EXISTS is_time(s text); 79 | DROP FUNCTION IF EXISTS is_date(s text, f text); 80 | DROP FUNCTION IF EXISTS is_json(s text); 81 | DROP FUNCTION IF EXISTS is_jsonb(s text); 82 | DROP FUNCTION IF EXISTS is_hex(s TEXT); 83 | DROP FUNCTION IF EXISTS hex2bigint(s TEXT); 84 | 85 | END; 86 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.7.0.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s text); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS array_trim(a text[], rd BOOLEAN); 34 | DROP FUNCTION IF EXISTS array_trim(a SMALLINT[], rd BOOLEAN); 35 | DROP FUNCTION IF EXISTS array_trim(a INTEGER[], rd BOOLEAN); 36 | DROP FUNCTION IF EXISTS array_trim(a BIGINT[], rd BOOLEAN); 37 | DROP FUNCTION IF EXISTS array_trim(a NUMERIC[], rd BOOLEAN); 38 | DROP FUNCTION IF EXISTS array_trim(a REAL[], rd BOOLEAN); 39 | DROP FUNCTION IF EXISTS array_trim(a DOUBLE PRECISION[], rd BOOLEAN); 40 | DROP FUNCTION IF EXISTS array_trim(a DATE[], rd BOOLEAN); 41 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP[], rd BOOLEAN); 42 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP WITH TIME ZONE[], rd BOOLEAN); 43 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 44 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 45 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 46 | DROP FUNCTION IF EXISTS date_de(d DATE); 47 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 48 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 49 | DROP FUNCTION IF EXISTS replace_latin1(s text, s_search text[], s_replace text[]); 50 | DROP FUNCTION IF EXISTS replace_latin1(s text, replacement text); 51 | DROP FUNCTION IF EXISTS replace_latin1(s text); 52 | DROP FUNCTION IF EXISTS replace_encoding(s text, s_search text[], s_replace text[]); 53 | DROP FUNCTION IF EXISTS replace_encoding(s text, e text, replacement text); 54 | DROP FUNCTION IF EXISTS replace_encoding(s text, e text); 55 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s text, e text); 56 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s text); 57 | DROP FUNCTION IF EXISTS is_latin1(s text); 58 | DROP FUNCTION IF EXISTS is_encoding(s text, enc text, enc_from text); 59 | DROP FUNCTION IF EXISTS is_encoding(s text, enc text); 60 | DROP VIEW IF EXISTS pg_functions; 61 | DROP VIEW IF EXISTS pg_foreign_keys; 62 | DROP VIEW IF EXISTS pg_db_views; 63 | DROP VIEW IF EXISTS pg_table_matview_infos; 64 | DROP VIEW IF EXISTS pg_object_ownership; 65 | DROP VIEW IF EXISTS pg_bloat_info; 66 | DROP VIEW IF EXISTS pg_unused_indexes; 67 | DROP FUNCTION IF EXISTS pg_schema_size(text); 68 | DROP FUNCTION IF EXISTS sha256(bytea); 69 | DROP FUNCTION IF EXISTS is_bigint(s text); 70 | DROP FUNCTION IF EXISTS is_integer(s text); 71 | DROP FUNCTION IF EXISTS is_smallint(s text); 72 | DROP FUNCTION IF EXISTS is_numeric(s text); 73 | DROP FUNCTION IF EXISTS is_real(s text); 74 | DROP FUNCTION IF EXISTS is_double_precision(s text); 75 | DROP FUNCTION IF EXISTS is_boolean(s text); 76 | DROP FUNCTION IF EXISTS is_json(s text); 77 | DROP FUNCTION IF EXISTS is_timestamp(s text, f text); 78 | DROP FUNCTION IF EXISTS is_timestamp(s text); 79 | DROP FUNCTION IF EXISTS is_time(s text, f text); 80 | DROP FUNCTION IF EXISTS is_time(s text); 81 | DROP FUNCTION IF EXISTS is_date(s text, f text); 82 | DROP FUNCTION IF EXISTS is_json(s text); 83 | DROP FUNCTION IF EXISTS is_jsonb(s text); 84 | DROP FUNCTION IF EXISTS is_hex(s TEXT); 85 | DROP FUNCTION IF EXISTS is_uuid(s TEXT); 86 | DROP FUNCTION IF EXISTS hex2bigint(s TEXT); 87 | DROP FUNCTION IF EXISTS is_bigint_array(s TEXT); 88 | DROP FUNCTION IF EXISTS is_integer_array(s TEXT); 89 | DROP FUNCTION IF EXISTS is_smallint_array(s TEXT); 90 | DROP FUNCTION IF EXISTS is_text_array(s TEXT); 91 | 92 | END; 93 | -------------------------------------------------------------------------------- /sql/out/uninstall/pgsql_tweaks_uninstall--0.7.1.sql: -------------------------------------------------------------------------------- 1 | /*** uninstall file to drop all objects created by the extension pgsql_tweaks ***/ 2 | 3 | BEGIN; 4 | 5 | DROP VIEW IF EXISTS pg_active_locks; 6 | DROP FUNCTION IF EXISTS is_empty(s text); 7 | DROP FUNCTION IF EXISTS array_sum(a BIGINT[]); 8 | DROP FUNCTION IF EXISTS array_sum(a INTEGER[]); 9 | DROP FUNCTION IF EXISTS array_sum(a SMALLINT[]); 10 | DROP FUNCTION IF EXISTS array_sum(a REAL[]); 11 | DROP FUNCTION IF EXISTS array_sum(a DOUBLE PRECISION[]); 12 | DROP FUNCTION IF EXISTS array_sum(a NUMERIC[]); 13 | DROP FUNCTION IF EXISTS array_avg(a BIGINT[]); 14 | DROP FUNCTION IF EXISTS array_avg(a INTEGER[]); 15 | DROP FUNCTION IF EXISTS array_avg(a SMALLINT[]); 16 | DROP FUNCTION IF EXISTS array_avg(a REAL[]); 17 | DROP FUNCTION IF EXISTS array_avg(a DOUBLE PRECISION[]); 18 | DROP FUNCTION IF EXISTS array_avg(a NUMERIC[]); 19 | DROP FUNCTION IF EXISTS array_min(a TEXT[]); 20 | DROP FUNCTION IF EXISTS array_min(a BIGINT[]); 21 | DROP FUNCTION IF EXISTS array_min(a INTEGER[]); 22 | DROP FUNCTION IF EXISTS array_min(a SMALLINT[]); 23 | DROP FUNCTION IF EXISTS array_min(a REAL[]); 24 | DROP FUNCTION IF EXISTS array_min(a DOUBLE PRECISION[]); 25 | DROP FUNCTION IF EXISTS array_min(a NUMERIC[]); 26 | DROP FUNCTION IF EXISTS array_max(a TEXT[]); 27 | DROP FUNCTION IF EXISTS array_max(a BIGINT[]); 28 | DROP FUNCTION IF EXISTS array_max(a INTEGER[]); 29 | DROP FUNCTION IF EXISTS array_max(a NUMERIC[]); 30 | DROP FUNCTION IF EXISTS array_max(a REAL[]); 31 | DROP FUNCTION IF EXISTS array_max(a DOUBLE PRECISION[]); 32 | DROP FUNCTION IF EXISTS array_max(a SMALLINT[]); 33 | DROP FUNCTION IF EXISTS array_trim(a text[], rd BOOLEAN); 34 | DROP FUNCTION IF EXISTS array_trim(a SMALLINT[], rd BOOLEAN); 35 | DROP FUNCTION IF EXISTS array_trim(a INTEGER[], rd BOOLEAN); 36 | DROP FUNCTION IF EXISTS array_trim(a BIGINT[], rd BOOLEAN); 37 | DROP FUNCTION IF EXISTS array_trim(a NUMERIC[], rd BOOLEAN); 38 | DROP FUNCTION IF EXISTS array_trim(a REAL[], rd BOOLEAN); 39 | DROP FUNCTION IF EXISTS array_trim(a DOUBLE PRECISION[], rd BOOLEAN); 40 | DROP FUNCTION IF EXISTS array_trim(a DATE[], rd BOOLEAN); 41 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP[], rd BOOLEAN); 42 | DROP FUNCTION IF EXISTS array_trim(a TIMESTAMP WITH TIME ZONE[], rd BOOLEAN); 43 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp with time zone); 44 | DROP FUNCTION IF EXISTS to_unix_timestamp(ts timestamp); 45 | DROP FUNCTION IF EXISTS datetime_de(t TIMESTAMP WITH TIME ZONE, with_tz BOOLEAN); 46 | DROP FUNCTION IF EXISTS date_de(d DATE); 47 | DROP AGGREGATE IF EXISTS gap_fill(anyelement); 48 | DROP FUNCTION IF EXISTS gap_fill_internal(s anyelement, v anyelement); 49 | DROP FUNCTION IF EXISTS replace_latin1(s text, s_search text[], s_replace text[]); 50 | DROP FUNCTION IF EXISTS replace_latin1(s text, replacement text); 51 | DROP FUNCTION IF EXISTS replace_latin1(s text); 52 | DROP FUNCTION IF EXISTS replace_encoding(s text, s_search text[], s_replace text[]); 53 | DROP FUNCTION IF EXISTS replace_encoding(s text, e text, replacement text); 54 | DROP FUNCTION IF EXISTS replace_encoding(s text, e text); 55 | DROP FUNCTION IF EXISTS return_not_part_of_encoding(s text, e text); 56 | DROP FUNCTION IF EXISTS return_not_part_of_latin1(s text); 57 | DROP FUNCTION IF EXISTS is_latin1(s text); 58 | DROP FUNCTION IF EXISTS is_encoding(s text, enc text, enc_from text); 59 | DROP FUNCTION IF EXISTS is_encoding(s text, enc text); 60 | DROP VIEW IF EXISTS pg_functions; 61 | DROP VIEW IF EXISTS pg_foreign_keys; 62 | DROP VIEW IF EXISTS pg_db_views; 63 | DROP VIEW IF EXISTS pg_table_matview_infos; 64 | DROP VIEW IF EXISTS pg_object_ownership; 65 | DROP VIEW IF EXISTS pg_bloat_info; 66 | DROP VIEW IF EXISTS pg_unused_indexes; 67 | DROP FUNCTION IF EXISTS pg_schema_size(text); 68 | DROP FUNCTION IF EXISTS sha256(bytea); 69 | DROP FUNCTION IF EXISTS is_bigint(s text); 70 | DROP FUNCTION IF EXISTS is_integer(s text); 71 | DROP FUNCTION IF EXISTS is_smallint(s text); 72 | DROP FUNCTION IF EXISTS is_numeric(s text); 73 | DROP FUNCTION IF EXISTS is_real(s text); 74 | DROP FUNCTION IF EXISTS is_double_precision(s text); 75 | DROP FUNCTION IF EXISTS is_boolean(s text); 76 | DROP FUNCTION IF EXISTS is_json(s text); 77 | DROP FUNCTION IF EXISTS is_timestamp(s text, f text); 78 | DROP FUNCTION IF EXISTS is_timestamp(s text); 79 | DROP FUNCTION IF EXISTS is_time(s text, f text); 80 | DROP FUNCTION IF EXISTS is_time(s text); 81 | DROP FUNCTION IF EXISTS is_date(s text, f text); 82 | DROP FUNCTION IF EXISTS is_json(s text); 83 | DROP FUNCTION IF EXISTS is_jsonb(s text); 84 | DROP FUNCTION IF EXISTS is_hex(s TEXT); 85 | DROP FUNCTION IF EXISTS is_uuid(s TEXT); 86 | DROP FUNCTION IF EXISTS hex2bigint(s TEXT); 87 | DROP FUNCTION IF EXISTS is_bigint_array(s TEXT); 88 | DROP FUNCTION IF EXISTS is_integer_array(s TEXT); 89 | DROP FUNCTION IF EXISTS is_smallint_array(s TEXT); 90 | DROP FUNCTION IF EXISTS is_text_array(s TEXT); 91 | 92 | END; 93 | -------------------------------------------------------------------------------- /sql/view_pg_active_locks.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a view to get all connections and their locks. 3 | */ 4 | CREATE OR REPLACE VIEW pg_active_locks AS 5 | SELECT DISTINCT pid 6 | , state 7 | , datname 8 | , usename 9 | , application_name 10 | , client_addr 11 | , query_start 12 | , wait_event_type 13 | , wait_event 14 | , locktype 15 | , mode 16 | , query 17 | FROM pg_stat_activity AS a 18 | INNER JOIN pg_locks AS l 19 | USING(pid) 20 | ; 21 | COMMENT ON VIEW pg_active_locks IS 'Creates a view to get all connections and their locks'; 22 | -------------------------------------------------------------------------------- /sql/view_pg_bloat_info.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * The view shows bloat in tables and indexes. 3 | */ 4 | CREATE OR REPLACE VIEW pg_bloat_info AS 5 | WITH constants AS 6 | ( 7 | SELECT current_setting('block_size')::numeric AS bs 8 | , 23 AS hdr 9 | , 4 AS ma 10 | ) 11 | , bloat_info AS 12 | ( 13 | SELECT ma 14 | ,bs 15 | ,schemaname 16 | ,tablename 17 | , (datawidth + (hdr + ma - (case when hdr%ma = 0 THEN ma ELSE hdr%ma END)))::numeric AS datahdr 18 | , (maxfracsum * (nullhdr + ma - (case when nullhdr%ma = 0 THEN ma ELSE nullhdr%ma END))) AS nullhdr2 19 | FROM 20 | ( 21 | SELECT schemaname 22 | , tablename 23 | , hdr 24 | , ma 25 | , bs 26 | , sum ((1 - null_frac) * avg_width) AS datawidth 27 | , max (null_frac) AS maxfracsum 28 | , hdr + 29 | ( 30 | SELECT 1 + count(*) / 8 31 | FROM pg_stats s2 32 | WHERE null_frac != 0 33 | AND s2.schemaname = s.schemaname 34 | AND s2.tablename = s.tablename 35 | ) AS nullhdr 36 | FROM pg_stats AS s, constants 37 | GROUP BY 1 38 | ,2 39 | ,3 40 | ,4 41 | ,5 42 | ) AS foo 43 | ) 44 | , table_bloat AS 45 | ( 46 | SELECT schemaname 47 | , tablename 48 | , cc.relpages 49 | , bs 50 | , CEIL ((cc.reltuples * ((datahdr + ma - (CASE WHEN datahdr%ma = 0 THEN ma ELSE datahdr%ma END)) + nullhdr2 + 4)) / (bs - 20::float)) AS otta 51 | FROM bloat_info 52 | INNER JOIN pg_class cc 53 | ON cc.relname = bloat_info.tablename 54 | INNER JOIN pg_namespace nn 55 | ON cc.relnamespace = nn.oid 56 | AND nn.nspname = bloat_info.schemaname 57 | AND nn.nspname NOT IN 58 | ( 59 | 'information_schema', 60 | 'pg_catalog' 61 | ) 62 | ) 63 | , index_bloat AS 64 | ( 65 | SELECT schemaname 66 | , tablename 67 | , bs 68 | , COALESCE (c2.relname,'?') AS iname 69 | , COALESCE (c2.reltuples,0) AS ituples 70 | , COALESCE (c2.relpages,0) AS ipages 71 | , COALESCE (CEIL ((c2.reltuples * (datahdr - 12)) / (bs - 20::float)), 0) AS iotta -- very rough approximation, assumes all cols 72 | FROM bloat_info 73 | INNER JOIN pg_class AS cc 74 | ON cc.relname = bloat_info.tablename 75 | INNER JOIN pg_namespace AS nn 76 | ON cc.relnamespace = nn.oid 77 | AND nn.nspname = bloat_info.schemaname 78 | AND nn.nspname NOT IN 79 | ( 80 | 'information_schema', 81 | 'pg_catalog' 82 | ) 83 | INNER JOIN pg_index AS i 84 | ON indrelid = cc.oid 85 | INNER JOIN pg_class AS c2 86 | ON c2.oid = i.indexrelid 87 | ) 88 | SELECT type 89 | , schemaname 90 | , object_name 91 | , bloat 92 | , pg_size_pretty(raw_waste) AS waste 93 | FROM 94 | ( 95 | SELECT 'table' AS type 96 | , schemaname 97 | , tablename AS object_name 98 | , ROUND (CASE WHEN otta = 0 THEN 0.0 ELSE table_bloat.relpages/otta::numeric END, 1) AS bloat 99 | , CASE WHEN relpages < otta THEN '0' ELSE (bs * (table_bloat.relpages-otta)::bigint)::bigint END AS raw_waste 100 | FROM table_bloat 101 | UNION 102 | SELECT 'index' AS type 103 | , schemaname 104 | , tablename || '::' || iname as object_name 105 | , ROUND (CASE WHEN iotta = 0 OR ipages = 0 THEN 0.0 ELSE ipages / iotta::numeric END, 1) AS bloat 106 | , CASE WHEN ipages < iotta THEN '0' ELSE (bs*(ipages-iotta))::bigint END AS raw_waste 107 | FROM index_bloat 108 | ) AS bloat_summary 109 | ORDER BY raw_waste DESC 110 | , bloat DESC 111 | ; 112 | COMMENT ON VIEW pg_bloat_info IS 'The view shows bloat in tables and indexes.'; 113 | -------------------------------------------------------------------------------- /sql/view_pg_db_views.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a view to get all views of the current database but excluding system views and all views which do start with 'pg' or '_pg'. 3 | */ 4 | CREATE OR REPLACE VIEW pg_db_views AS 5 | SELECT table_catalog AS view_catalog 6 | , table_schema AS view_schema 7 | , table_name AS view_name 8 | , view_definition 9 | FROM INFORMATION_SCHEMA.views 10 | WHERE NOT table_name LIKE 'pg%' 11 | AND NOT table_name LIKE '\\_pg%' 12 | AND table_schema NOT IN ('pg_catalog', 'information_schema') 13 | ORDER BY table_catalog 14 | , table_schema 15 | , table_name 16 | ; 17 | COMMENT ON VIEW pg_db_views IS 'Creates a view to get all views of the current database but excluding system views and all views which do start with ''pg'' or ''_pg'''; 18 | -------------------------------------------------------------------------------- /sql/view_pg_foreign_keys.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a view to get all foreign keys of the current database. 3 | */ 4 | DO $$ 5 | DECLARE 6 | version_11_greater BOOLEAN; 7 | BEGIN 8 | SELECT to_number((string_to_array(version(), ' '))[2], '999.99') >= 11 INTO version_11_greater; 9 | 10 | DROP VIEW IF EXISTS pg_foreign_keys; 11 | 12 | IF version_11_greater THEN 13 | -- Only version 11 or newer 14 | CREATE OR REPLACE VIEW pg_foreign_keys AS 15 | SELECT ccu.constraint_name 16 | , tc.is_deferrable 17 | , tc.initially_deferred 18 | , tc."enforced" 19 | , tc.table_schema 20 | , tc.table_name 21 | , kcu.column_name 22 | , ccu.table_schema AS foreign_table_schema 23 | , ccu.TABLE_NAME AS foreign_table_name 24 | , ccu.COLUMN_NAME AS foreign_column_name 25 | , EXISTS 26 | ( 27 | SELECT 1 28 | FROM pg_catalog.pg_index AS i 29 | WHERE i.indrelid = cs.conrelid 30 | AND i.indpred IS NULL 31 | AND (i.indkey::smallint[])[0:cardinality(cs.conkey)-1] OPERATOR(pg_catalog.@>) cs.conkey 32 | ) AS is_indexed 33 | FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc 34 | INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS kcu 35 | ON tc.CONSTRAINT_NAME = kcu.CONSTRAINT_NAME 36 | INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS ccu 37 | ON ccu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME 38 | INNER JOIN PG_CATALOG.PG_NAMESPACE AS n 39 | ON tc.table_schema = n.nspname 40 | INNER JOIN PG_CATALOG.PG_CONSTRAINT AS cs 41 | ON n."oid" = cs.connamespace 42 | AND tc.constraint_name = cs.conname 43 | WHERE tc.CONSTRAINT_TYPE = 'FOREIGN KEY' 44 | ; 45 | ELSE 46 | -- Older than version 11 47 | CREATE OR REPLACE VIEW pg_foreign_keys AS 48 | SELECT ccu.constraint_name 49 | , tc.is_deferrable 50 | , tc.initially_deferred 51 | , tc.table_schema 52 | , tc.table_name 53 | , kcu.column_name 54 | , ccu.table_schema AS foreign_table_schema 55 | , ccu.TABLE_NAME AS foreign_table_name 56 | , ccu.COLUMN_NAME AS foreign_column_name 57 | , EXISTS 58 | ( 59 | SELECT 1 60 | FROM pg_catalog.pg_index AS i 61 | WHERE i.indrelid = cs.conrelid 62 | AND i.indpred IS NULL 63 | AND (i.indkey::smallint[])[0:cardinality(cs.conkey)-1] OPERATOR(pg_catalog.@>) cs.conkey 64 | ) AS is_indexed 65 | FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc 66 | INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS kcu 67 | ON tc.CONSTRAINT_NAME = kcu.CONSTRAINT_NAME 68 | INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS ccu 69 | ON ccu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME 70 | INNER JOIN PG_CATALOG.PG_NAMESPACE AS n 71 | ON tc.table_schema = n.nspname 72 | INNER JOIN PG_CATALOG.PG_CONSTRAINT AS cs 73 | ON n."oid" = cs.connamespace 74 | AND tc.constraint_name = cs.conname 75 | WHERE tc.CONSTRAINT_TYPE = 'FOREIGN KEY' 76 | ; 77 | END IF; 78 | 79 | COMMENT ON VIEW pg_foreign_keys IS 'The view returns all foreign keys of the current database'; 80 | 81 | END $$; 82 | -------------------------------------------------------------------------------- /sql/view_pg_functions.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a view to get all functions of the current database. 3 | * This is the script handles the different installations which are needed for 4 | * PostgreSQL 11 or newer and PostgreSQL 10 or older. 5 | */ 6 | DO $$ 7 | DECLARE 8 | version_greater_11 BOOLEAN; 9 | BEGIN 10 | SELECT to_number((string_to_array(version(), ' '))[2], '999.99') >= 11 INTO version_greater_11; 11 | 12 | IF version_greater_11 THEN 13 | -- Create the view pg_functions for PostgreSQL 11 or newer 14 | CREATE OR REPLACE VIEW pg_functions AS 15 | SELECT pg_namespace.nspname AS schema_name 16 | , pg_proc.proname AS function_name 17 | , pg_catalog.pg_get_function_result(pg_proc.oid) AS returning_data_type 18 | , pg_catalog.pg_get_function_arguments(pg_proc.oid) AS parameters 19 | , CASE 20 | WHEN pg_proc.prokind = 'a' THEN 21 | 'aggregate' 22 | WHEN pg_proc.prokind = 'w' THEN 23 | 'window' 24 | WHEN pg_proc.prokind = 'f' THEN 25 | 'function' 26 | WHEN pg_proc.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN 27 | 'trigger' 28 | ELSE 29 | 'unknown' 30 | END as function_type 31 | , pg_description.description AS function_comment 32 | FROM pg_catalog.pg_proc 33 | LEFT OUTER JOIN pg_catalog.pg_namespace 34 | ON pg_proc.pronamespace = pg_namespace.oid 35 | LEFT OUTER JOIN pg_catalog.pg_description 36 | ON pg_proc.oid = pg_description.objoid 37 | WHERE pg_catalog.pg_function_is_visible(pg_proc.oid) 38 | AND pg_namespace.nspname NOT IN ('pg_catalog', 'information_schema') 39 | ORDER BY schema_name 40 | , function_name 41 | , parameters 42 | ; 43 | ELSE 44 | -- Create the view pg_functions for PostgreSQL older than 11 45 | CREATE OR REPLACE VIEW pg_functions AS 46 | SELECT pg_namespace.nspname AS schema_name 47 | , pg_proc.proname AS function_name 48 | , pg_catalog.pg_get_function_result(pg_proc.oid) AS returning_data_type 49 | , pg_catalog.pg_get_function_arguments(pg_proc.oid) AS parameters 50 | , CASE 51 | WHEN pg_proc.proisagg THEN 52 | 'aggregate' 53 | WHEN pg_proc.proiswindow THEN 54 | 'window' 55 | WHEN pg_proc.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN 56 | 'trigger' 57 | ELSE 58 | 'function' 59 | END as function_type 60 | , pg_description.description AS function_comment 61 | FROM pg_catalog.pg_proc 62 | LEFT OUTER JOIN pg_catalog.pg_namespace 63 | ON pg_proc.pronamespace = pg_namespace.oid 64 | LEFT OUTER JOIN pg_catalog.pg_description 65 | ON pg_proc.oid = pg_description.objoid 66 | WHERE pg_catalog.pg_function_is_visible(pg_proc.oid) 67 | AND pg_namespace.nspname NOT IN ('pg_catalog', 'information_schema') 68 | ORDER BY schema_name 69 | , function_name 70 | , parameters 71 | ; 72 | END IF; 73 | 74 | -- Add a comment 75 | COMMENT ON VIEW pg_functions IS 'The view returns all functions of the current database, excluding those in the schema pg_catalog and information_schema'; 76 | 77 | END $$; 78 | -------------------------------------------------------------------------------- /sql/view_pg_partitioned_tables_infos.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a view to get information about partitioned tables. 3 | */ 4 | DO $$ 5 | DECLARE 6 | version_greater_10 BOOLEAN; 7 | BEGIN 8 | SELECT to_number((string_to_array(version(), ' '))[2], '999.99') >= 10 INTO version_greater_10; 9 | 10 | IF version_greater_10 THEN 11 | -- Create the view pg_functions for PostgreSQL 10 or newer 12 | CREATE OR REPLACE VIEW pg_partitioned_tables_infos AS 13 | SELECT cl.oid AS parent_relid 14 | , n.nspname AS parent_schemaname 15 | , cl.relname AS parent_tablename 16 | , r.rolname AS parent_owner 17 | , CASE pt.partstrat 18 | WHEN 'l' THEN 19 | 'LIST' 20 | WHEN 'r' THEN 21 | 'RANGE' 22 | WHEN 'h' THEN 23 | 'HASH' 24 | END AS partition_strategy 25 | , count (cl2.oid) OVER (PARTITION BY cl.oid) AS count_of_partitions 26 | , COALESCE (sum (pg_relation_size (cl2.oid)) OVER (PARTITION BY cl.oid), 0) AS overall_size 27 | , cl2.oid AS child_relid 28 | , n2.nspname AS child_schemaname 29 | , cl2.relname AS child_tablename 30 | , r2.rolname AS child_owner 31 | , pg_relation_size (cl2.oid) AS child_size 32 | FROM pg_catalog.pg_class AS cl 33 | INNER JOIN pg_catalog.pg_partitioned_table AS pt 34 | ON cl.oid = pt.partrelid 35 | INNER JOIN pg_catalog.pg_namespace AS n 36 | ON cl.relnamespace = n.oid 37 | INNER JOIN pg_catalog.pg_roles AS r 38 | ON cl.relowner = r.oid 39 | LEFT OUTER JOIN pg_catalog.pg_inherits AS i 40 | ON cl.oid = i.inhparent 41 | LEFT OUTER JOIN pg_catalog.pg_class AS cl2 42 | ON i.inhrelid = cl2.oid 43 | AND cl2.relispartition 44 | AND cl2.relkind = 'r' 45 | LEFT OUTER JOIN pg_catalog.pg_namespace AS n2 46 | ON cl2.relnamespace = n2.oid 47 | LEFT OUTER JOIN pg_catalog.pg_roles AS r2 48 | ON cl2.relowner = r2.oid 49 | WHERE cl.relkind = 'p' 50 | ; 51 | 52 | COMMENT ON VIEW pg_partitioned_tables_infos IS 'Creates a view to get information about partitioned tables'; 53 | END IF; 54 | 55 | END $$; 56 | -------------------------------------------------------------------------------- /sql/view_pg_table_matview_infos.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Creates a view to get information about table and materialized views in the 3 | * current database. It includes their sizes and indexes. 4 | */ 5 | CREATE OR REPLACE VIEW pg_table_matview_infos AS 6 | WITH indexes AS 7 | ( 8 | SELECT schemaname 9 | , tablename 10 | , array_agg(indexname) AS indexes 11 | FROM pg_indexes 12 | GROUP BY schemaname 13 | , tablename 14 | ) 15 | SELECT 'table' AS type 16 | , n.nspname AS schemaname 17 | , c.relname AS tablename 18 | , pg_get_userbyid (c.relowner) AS tableowner 19 | , t.spcname AS TABLESPACE 20 | , i.indexes 21 | , pg_table_size (c.oid) AS table_size 22 | , pg_indexes_size(c.oid) AS indexes_size 23 | , pg_total_relation_size(c.oid) AS total_relation_size 24 | , pg_size_pretty(pg_table_size(c.oid)) AS table_size_pretty 25 | , pg_size_pretty(pg_indexes_size(c.oid)) AS indexes_size_pretty 26 | , pg_size_pretty(pg_total_relation_size(c.oid)) AS total_relation_size_pretty 27 | FROM pg_class AS c 28 | LEFT OUTER JOIN pg_namespace AS n 29 | ON n.oid = c.relnamespace 30 | LEFT OUTER JOIN pg_tablespace AS t 31 | ON t.oid = c.reltablespace 32 | LEFT OUTER JOIN indexes AS i 33 | ON n.nspname = i.schemaname 34 | AND c.relname = i.tablename 35 | WHERE c.relkind = ANY (ARRAY['r'::"char", 'p'::"char"]) 36 | AND n.nspname NOT IN ('pg_catalog', 'information_schema') 37 | UNION ALL 38 | SELECT 'matview' AS type 39 | , n.nspname AS schemaname 40 | , c.relname AS matviewname 41 | , pg_get_userbyid(c.relowner) AS matviewowner 42 | , t.spcname AS tablespace 43 | , i.indexes 44 | , pg_table_size(c.oid) AS table_size 45 | , pg_indexes_size(c.oid) AS indexes_size 46 | , pg_total_relation_size(c.oid) AS total_relation_size 47 | , pg_size_pretty(pg_table_size(c.oid)) AS table_size_pretty 48 | , pg_size_pretty(pg_indexes_size(c.oid)) AS indexes_size_pretty 49 | , pg_size_pretty(pg_total_relation_size(c.oid)) AS total_relation_size_pretty 50 | FROM pg_class AS c 51 | LEFT OUTER JOIN pg_namespace AS n 52 | ON n.oid = c.relnamespace 53 | LEFT OUTER JOIN pg_tablespace t 54 | ON t.oid = c.reltablespace 55 | LEFT OUTER JOIN indexes AS i 56 | ON n.nspname = i.schemaname 57 | AND c.relname = i.tablename 58 | WHERE c.relkind = 'm'::"char" 59 | ; 60 | COMMENT ON VIEW pg_table_matview_infos IS 'The view shows detailed information about sizes and indexes of tables and materialized views'; 61 | -------------------------------------------------------------------------------- /sql/view_pg_unused_indexes.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * The view shows unused indexes with further information about the table. 3 | */ 4 | CREATE OR REPLACE VIEW pg_unused_indexes AS 5 | SELECT schemaname 6 | , relname AS table_name 7 | , indexrelname AS index_name 8 | , idx_scan 9 | , pg_size_pretty (pg_table_size ('"' || schemaname || '"."' || relname || '"')) AS table_size 10 | , pg_size_pretty (pg_total_relation_size ('"' || schemaname || '"."' || relname || '"')) AS table_total_size 11 | , pg_size_pretty (pg_indexes_size ('"' || schemaname || '"."' || relname || '"')) AS all_indexes_size 12 | , pg_size_pretty (pg_relation_size (indexrelid)) AS index_size 13 | , pg_size_pretty (sum (pg_relation_size (indexrelid)) over ()) AS size_of_all_indexes 14 | FROM pg_stat_all_indexes 15 | WHERE idx_scan = 0 16 | AND schemaname NOT IN 17 | ( 18 | 'information_schema', 19 | 'pg_catalog', 20 | 'pg_toast' 21 | ) 22 | ; 23 | COMMENT ON VIEW pg_unused_indexes IS 'The view shows unused indexes with further information about the table.'; 24 | -------------------------------------------------------------------------------- /test/sql/aggregate_function_gap_fill.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for the aggregate gap_fill 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT count(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'gap_fill_internal' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test if the aggregate exists 27 | WITH test AS 28 | ( 29 | SELECT count(*) AS exist 30 | , 0 AS zero 31 | FROM pg_catalog.pg_proc 32 | WHERE proname = 'gap_fill' 33 | ) 34 | SELECT 35 | CASE 36 | WHEN 1 / test.exist = 1 THEN 37 | TRUE 38 | ELSE 39 | (1 / zero)::BOOLEAN 40 | END AS res 41 | FROM test 42 | ; 43 | 44 | -- Create a table with some test values 45 | CREATE TABLE test_gap_fill(id INTEGER, some_value text); 46 | 47 | INSERT INTO test_gap_fill(id, some_value) VALUES 48 | (1, 'value 1'), 49 | (1, NULL), 50 | (2, 'value 2'), 51 | (2, NULL), 52 | (2, NULL), 53 | (3, 'value 3') 54 | ; 55 | 56 | -- Select the test data and return filled columns, the count of colums should be 57 | -- the same number as the count of not empty ones 58 | WITH t1 AS 59 | ( 60 | SELECT id 61 | , gap_fill(some_value) OVER (ORDER BY id) AS some_value 62 | , 0 AS zero 63 | FROM test_gap_fill 64 | ) 65 | SELECT 66 | CASE 67 | WHEN count(*) / count(*) FILTER (WHERE NOT some_value IS NULL) = 1 THEN 68 | TRUE 69 | ELSE 70 | (1 / zero)::BOOLEAN 71 | END AS res 72 | FROM t1 73 | GROUP BY zero 74 | ; 75 | 76 | ROLLBACK; 77 | -------------------------------------------------------------------------------- /test/sql/function_array_avg.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for the functions array_avg 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT count(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'array_avg' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 6 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / test.zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test if all six implementations exists 27 | WITH test AS 28 | ( 29 | SELECT count(*) AS exist 30 | , 0 AS zero 31 | FROM pg_catalog.pg_proc 32 | WHERE proname = 'array_avg' 33 | ) 34 | SELECT 35 | CASE 36 | WHEN test.exist = 6 THEN 37 | TRUE 38 | ELSE 39 | (1 / test.zero)::BOOLEAN 40 | END AS res 41 | FROM test 42 | ; 43 | 44 | -- Test of the first implementation 45 | -- SMALLINT ARRAY 46 | WITH test AS 47 | ( 48 | SELECT array_avg(ARRAY[45, 60, 43, 99]::SMALLINT[]) AS avg_value 49 | , 0 AS zero 50 | ) 51 | SELECT 52 | CASE 53 | WHEN avg_value = 61.75 THEN 54 | TRUE 55 | ELSE 56 | (1 / test.zero)::BOOLEAN 57 | END AS res_1 58 | FROM test 59 | ; 60 | 61 | -- Test of the second implementation 62 | -- INTEGER ARRAY 63 | WITH test AS 64 | ( 65 | SELECT array_avg(ARRAY[45, 60, 43, 99]::INTEGER[]) AS avg_value 66 | , 0 AS zero 67 | ) 68 | SELECT 69 | CASE 70 | WHEN avg_value = 61.75 THEN 71 | TRUE 72 | ELSE 73 | (1 / test.zero)::BOOLEAN 74 | END AS res_1 75 | FROM test 76 | ; 77 | 78 | -- Test of the third implementation 79 | -- BIGINT ARRAY 80 | WITH test AS 81 | ( 82 | SELECT array_avg(ARRAY[45, 60, 43, 99]::BIGINT[]) AS avg_value 83 | , 0 AS zero 84 | ) 85 | SELECT 86 | CASE 87 | WHEN avg_value = 61.75 THEN 88 | TRUE 89 | ELSE 90 | (1 / test.zero)::BOOLEAN 91 | END AS res_1 92 | FROM test 93 | ; 94 | 95 | -- Test of the fourth implementation 96 | -- REAL ARRAY 97 | WITH test_data AS 98 | ( 99 | SELECT 45.6::REAL AS val 100 | UNION ALL 101 | SELECT 60.8::REAL 102 | UNION ALL 103 | SELECT 43::REAL 104 | UNION ALL 105 | SELECT 99.3::REAL 106 | ) 107 | , test AS 108 | ( 109 | SELECT array_avg(ARRAY[45.6, 60.8, 43, 99.3]::REAL[]) AS avg_value 110 | , 0 AS zero 111 | , avg(val) AS test_val 112 | FROM test_data 113 | ) 114 | SELECT 115 | CASE 116 | WHEN avg_value::NUMERIC = test_val::NUMERIC THEN 117 | TRUE 118 | ELSE 119 | (1 / test.zero)::BOOLEAN 120 | END AS res_1 121 | FROM test 122 | ; 123 | 124 | -- Test of the fifth implementation 125 | -- DOUBLE PRECISION ARRAY 126 | WITH test_data AS 127 | ( 128 | SELECT 45.6::DOUBLE PRECISION AS val 129 | UNION ALL 130 | SELECT 60.8::DOUBLE PRECISION 131 | UNION ALL 132 | SELECT 43::DOUBLE PRECISION 133 | UNION ALL 134 | SELECT 99.3::DOUBLE PRECISION 135 | ) 136 | , test AS 137 | ( 138 | SELECT array_avg(ARRAY[45.6, 60.8, 43, 99.3]::DOUBLE PRECISION[]) AS avg_value 139 | , 0 AS zero 140 | , avg(val) AS test_val 141 | FROM test_data 142 | ) 143 | SELECT 144 | CASE 145 | WHEN avg_value::NUMERIC = test_val::NUMERIC THEN 146 | TRUE 147 | ELSE 148 | (1 / test.zero)::BOOLEAN 149 | END AS res_1 150 | FROM test 151 | ; 152 | 153 | -- Test of the sicth implementation 154 | -- NUMERIC ARRAY 155 | WITH test_data AS 156 | ( 157 | SELECT 45.6::NUMERIC AS val 158 | UNION ALL 159 | SELECT 60.8::NUMERIC 160 | UNION ALL 161 | SELECT 43::NUMERIC 162 | UNION ALL 163 | SELECT 99.3::NUMERIC 164 | ) 165 | , test AS 166 | ( 167 | SELECT array_avg(ARRAY[45.6, 60.8, 43, 99.3]::NUMERIC[]) AS avg_value 168 | , 0 AS zero 169 | , avg(val) AS test_val 170 | FROM test_data 171 | ) 172 | SELECT 173 | CASE 174 | WHEN avg_value::NUMERIC = test_val::NUMERIC THEN 175 | TRUE 176 | ELSE 177 | (1 / test.zero)::BOOLEAN 178 | END AS res_1 179 | FROM test 180 | ; 181 | 182 | ROLLBACK; 183 | -------------------------------------------------------------------------------- /test/sql/function_array_max.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for the functions array_max 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT count(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'array_max' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 7 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / test.zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test if all seven implementations exists 27 | WITH test AS 28 | ( 29 | SELECT count(*) AS exist 30 | , 0 AS zero 31 | FROM pg_catalog.pg_proc 32 | WHERE proname = 'array_max' 33 | ) 34 | SELECT 35 | CASE 36 | WHEN test.exist = 7 THEN 37 | TRUE 38 | ELSE 39 | (1 / test.zero)::BOOLEAN 40 | END AS res 41 | FROM test 42 | ; 43 | 44 | -- Test of the first implementation 45 | -- SMALLINT ARRAY 46 | WITH test AS 47 | ( 48 | SELECT array_max(ARRAY[45, 60, 43, 99]::SMALLINT[]) AS max_value 49 | , 0 AS zero 50 | ) 51 | SELECT 52 | CASE 53 | WHEN max_value = 99 THEN 54 | TRUE 55 | ELSE 56 | (1 / test.zero)::BOOLEAN 57 | END AS res_1 58 | FROM test 59 | ; 60 | 61 | -- Test of the second implementation 62 | -- INTEGER ARRAY 63 | WITH test AS 64 | ( 65 | SELECT array_max(ARRAY[45, 60, 43, 99]::INTEGER[]) AS max_value 66 | , 0 AS zero 67 | ) 68 | SELECT 69 | CASE 70 | WHEN max_value = 99 THEN 71 | TRUE 72 | ELSE 73 | (1 / test.zero)::BOOLEAN 74 | END AS res_1 75 | FROM test 76 | ; 77 | 78 | -- Test of the third implementation 79 | -- BIGINT ARRAY 80 | WITH test AS 81 | ( 82 | SELECT array_max(ARRAY[45, 60, 43, 99]::BIGINT[]) AS max_value 83 | , 0 AS zero 84 | ) 85 | SELECT 86 | CASE 87 | WHEN max_value = 99 THEN 88 | TRUE 89 | ELSE 90 | (1 / test.zero)::BOOLEAN 91 | END AS res_1 92 | FROM test 93 | ; 94 | 95 | -- Test of the fourth implementation 96 | -- TEXT ARRAY 97 | WITH test AS 98 | ( 99 | SELECT array_max(ARRAY['def', 'abc', 'ghi']::TEXT[]) AS max_value 100 | , 0 AS zero 101 | ) 102 | SELECT 103 | CASE 104 | WHEN max_value = 'ghi' THEN 105 | TRUE 106 | ELSE 107 | (1 / test.zero)::BOOLEAN 108 | END AS res_1 109 | FROM test 110 | ; 111 | 112 | -- Test of the fifth implementation 113 | -- REAL ARRAY 114 | WITH test AS 115 | ( 116 | SELECT array_max(ARRAY[45.6, 60.8, 43, 99.3]::REAL[]) AS max_value 117 | , 0 AS zero 118 | ) 119 | SELECT 120 | CASE 121 | WHEN max_value = 99.3 THEN 122 | TRUE 123 | ELSE 124 | (1 / test.zero)::BOOLEAN 125 | END AS res_1 126 | FROM test 127 | ; 128 | 129 | -- Test of the sixth implementation 130 | -- DOUBLE PRECISION ARRAY 131 | WITH test AS 132 | ( 133 | SELECT array_max(ARRAY[45.6, 60.8, 43, 99.3]::DOUBLE PRECISION[]) AS max_value 134 | , 0 AS zero 135 | ) 136 | SELECT 137 | CASE 138 | WHEN max_value = 99.3 THEN 139 | TRUE 140 | ELSE 141 | (1 / test.zero)::BOOLEAN 142 | END AS res_1 143 | FROM test 144 | ; 145 | 146 | -- Test of the seventh implementation 147 | -- NUMERIC ARRAY 148 | WITH test AS 149 | ( 150 | SELECT array_max(ARRAY[45.6, 60.8, 43, 99.3]::NUMERIC[]) AS max_value 151 | , 0 AS zero 152 | ) 153 | SELECT 154 | CASE 155 | WHEN max_value = 99.3 THEN 156 | TRUE 157 | ELSE 158 | (1 / test.zero)::BOOLEAN 159 | END AS res_1 160 | FROM test 161 | ; 162 | 163 | ROLLBACK; 164 | -------------------------------------------------------------------------------- /test/sql/function_array_min.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for the functions array_min 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT count(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'array_min' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 7 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / test.zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test if all seven implementations exists 27 | WITH test AS 28 | ( 29 | SELECT count(*) AS exist 30 | , 0 AS zero 31 | FROM pg_catalog.pg_proc 32 | WHERE proname = 'array_min' 33 | ) 34 | SELECT 35 | CASE 36 | WHEN test.exist = 7 THEN 37 | TRUE 38 | ELSE 39 | (1 / test.zero)::BOOLEAN 40 | END AS res 41 | FROM test 42 | ; 43 | 44 | -- Test of the first implementation 45 | -- SMALLINT ARRAY 46 | WITH test AS 47 | ( 48 | SELECT array_min(ARRAY[45, 60, 43, 99]::SMALLINT[]) AS min_value 49 | , 0 AS zero 50 | ) 51 | SELECT 52 | CASE 53 | WHEN min_value = 43 THEN 54 | TRUE 55 | ELSE 56 | (1 / test.zero)::BOOLEAN 57 | END AS res_1 58 | FROM test 59 | ; 60 | 61 | -- Test of the second implementation 62 | -- INTEGER ARRAY 63 | WITH test AS 64 | ( 65 | SELECT array_min(ARRAY[45, 60, 43, 99]::INTEGER[]) AS min_value 66 | , 0 AS zero 67 | ) 68 | SELECT 69 | CASE 70 | WHEN min_value = 43 THEN 71 | TRUE 72 | ELSE 73 | (1 / test.zero)::BOOLEAN 74 | END AS res_1 75 | FROM test 76 | ; 77 | 78 | -- Test of the third implementation 79 | -- BIGINT ARRAY 80 | WITH test AS 81 | ( 82 | SELECT array_min(ARRAY[45, 60, 43, 99]::BIGINT[]) AS min_value 83 | , 0 AS zero 84 | ) 85 | SELECT 86 | CASE 87 | WHEN min_value = 43 THEN 88 | TRUE 89 | ELSE 90 | (1 / test.zero)::BOOLEAN 91 | END AS res_1 92 | FROM test 93 | ; 94 | 95 | -- Test of the fourth implementation 96 | -- TEXT ARRAY 97 | WITH test AS 98 | ( 99 | SELECT array_min(ARRAY['def', 'abc', 'ghi']::TEXT[]) AS min_value 100 | , 0 AS zero 101 | ) 102 | SELECT 103 | CASE 104 | WHEN min_value = 'abc' THEN 105 | TRUE 106 | ELSE 107 | (1 / test.zero)::BOOLEAN 108 | END AS res_1 109 | FROM test 110 | ; 111 | 112 | -- Test of the fifth implementation 113 | -- REAL ARRAY 114 | WITH test AS 115 | ( 116 | SELECT array_min(ARRAY[45.6, 60.8, 43.7, 99.3]::REAL[]) AS min_value 117 | , 0 AS zero 118 | ) 119 | SELECT 120 | CASE 121 | WHEN min_value = 43.7 THEN 122 | TRUE 123 | ELSE 124 | (1 / test.zero)::BOOLEAN 125 | END AS res_1 126 | FROM test 127 | ; 128 | 129 | -- Test of the sixth implementation 130 | -- DOUBLE PRECISION ARRAY 131 | WITH test AS 132 | ( 133 | SELECT array_min(ARRAY[45.6, 60.8, 43.7, 99.3]::DOUBLE PRECISION[]) AS min_value 134 | , 0 AS zero 135 | ) 136 | SELECT 137 | CASE 138 | WHEN min_value = 43.7 THEN 139 | TRUE 140 | ELSE 141 | (1 / test.zero)::BOOLEAN 142 | END AS res_1 143 | FROM test 144 | ; 145 | 146 | -- Test of the seventh implementation 147 | -- NUMERIC ARRAY 148 | WITH test AS 149 | ( 150 | SELECT array_min(ARRAY[45.6, 60.8, 43.7, 99.3]::NUMERIC[]) AS min_value 151 | , 0 AS zero 152 | ) 153 | SELECT 154 | CASE 155 | WHEN min_value = 43.7 THEN 156 | TRUE 157 | ELSE 158 | (1 / test.zero)::BOOLEAN 159 | END AS res_1 160 | FROM test 161 | ; 162 | 163 | ROLLBACK; 164 | -------------------------------------------------------------------------------- /test/sql/function_array_sum.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for the functions array_sum 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT count(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'array_sum' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 6 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / test.zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test if all six implementations exists 27 | WITH test AS 28 | ( 29 | SELECT count(*) AS exist 30 | , 0 AS zero 31 | FROM pg_catalog.pg_proc 32 | WHERE proname = 'array_sum' 33 | ) 34 | SELECT 35 | CASE 36 | WHEN test.exist = 6 THEN 37 | TRUE 38 | ELSE 39 | (1 / test.zero)::BOOLEAN 40 | END AS res 41 | FROM test 42 | ; 43 | 44 | -- Test of the first implementation 45 | -- SMALLINT ARRAY 46 | WITH test AS 47 | ( 48 | SELECT array_sum(ARRAY[45, 60, 43, 99]::SMALLINT[]) AS sum_value 49 | , 0 AS zero 50 | ) 51 | SELECT 52 | CASE 53 | WHEN sum_value = 247 THEN 54 | TRUE 55 | ELSE 56 | (1 / test.zero)::BOOLEAN 57 | END AS res_1 58 | FROM test 59 | ; 60 | 61 | -- Test of the second implementation 62 | -- INTEGER ARRAY 63 | WITH test AS 64 | ( 65 | SELECT array_sum(ARRAY[45, 60, 43, 99]::INTEGER[]) AS sum_value 66 | , 0 AS zero 67 | ) 68 | SELECT 69 | CASE 70 | WHEN sum_value = 247 THEN 71 | TRUE 72 | ELSE 73 | (1 / test.zero)::BOOLEAN 74 | END AS res_1 75 | FROM test 76 | ; 77 | 78 | -- Test of the third implementation 79 | -- BIGINT ARRAY 80 | WITH test AS 81 | ( 82 | SELECT array_sum(ARRAY[45, 60, 43, 99]::BIGINT[]) AS sum_value 83 | , 0 AS zero 84 | ) 85 | SELECT 86 | CASE 87 | WHEN sum_value = 247 THEN 88 | TRUE 89 | ELSE 90 | (1 / test.zero)::BOOLEAN 91 | END AS res_1 92 | FROM test 93 | ; 94 | 95 | -- Test of the fourth implementation 96 | -- REAL ARRAY 97 | WITH test AS 98 | ( 99 | SELECT array_sum(ARRAY[45.6, 60.8, 43.7, 99.3]::REAL[]) AS sum_value 100 | , 0 AS zero 101 | ) 102 | SELECT 103 | CASE 104 | WHEN sum_value = 249.4 THEN 105 | TRUE 106 | ELSE 107 | (1 / test.zero)::BOOLEAN 108 | END AS res_1 109 | FROM test 110 | ; 111 | 112 | -- Test of the fifth implementation 113 | -- DOUBLE PRECISION ARRAY 114 | WITH test AS 115 | ( 116 | SELECT array_sum(ARRAY[45.6, 60.8, 43.7, 99.3]::DOUBLE PRECISION[]) AS sum_value 117 | , 0 AS zero 118 | ) 119 | SELECT 120 | CASE 121 | WHEN sum_value = 249.4 THEN 122 | TRUE 123 | ELSE 124 | (1 / test.zero)::BOOLEAN 125 | END AS res_1 126 | FROM test 127 | ; 128 | 129 | -- Test of the sixth implementation 130 | -- NUMERIC ARRAY 131 | WITH test AS 132 | ( 133 | SELECT array_sum(ARRAY[45.6, 60.8, 43.7, 99.3]::NUMERIC[]) AS sum_value 134 | , 0 AS zero 135 | ) 136 | SELECT 137 | CASE 138 | WHEN sum_value = 249.4 THEN 139 | TRUE 140 | ELSE 141 | (1 / test.zero)::BOOLEAN 142 | END AS res_1 143 | FROM test 144 | ; 145 | 146 | ROLLBACK; 147 | -------------------------------------------------------------------------------- /test/sql/function_date_de.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function date_de 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'date_de' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Uses function is_date which is part of this repository 27 | WITH test AS 28 | ( 29 | SELECT date_de('2018-01-01') AS d_de 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN is_date(d_de, 'DD.MM.YYYY') THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | ROLLBACK; 43 | -------------------------------------------------------------------------------- /test/sql/function_datetime_de.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function datetime_de 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'datetime_de' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Uses function is_timestamp which is part of this repository 27 | WITH test AS 28 | ( 29 | SELECT datetime_de('2018-01-01 13:30:30 GMT') AS ts_de 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN is_timestamp(ts_de, 'DD.MM.YYYY HH24:MI:SS') THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | ROLLBACK; 43 | -------------------------------------------------------------------------------- /test/sql/function_hex2bigint.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function hex2bigint 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'hex2bigint' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test hexadicimal conversion 27 | WITH test AS 28 | ( 29 | SELECT hex2bigint('a1b0') = 41392 AS int_result 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN int_result THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | ROLLBACK; 43 | -------------------------------------------------------------------------------- /test/sql/function_is_bigint.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_bigint 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_bigint' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test integer 27 | WITH test AS 28 | ( 29 | SELECT is_bigint('123') AS isbigint 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN isbigint THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test a number with decimal separator, not a bigint 43 | WITH test AS 44 | ( 45 | SELECT is_bigint('123.456') AS isbigint 46 | , 0 AS zero 47 | ) 48 | SELECT 49 | CASE 50 | WHEN NOT isbigint THEN 51 | TRUE 52 | ELSE 53 | (1 / zero)::BOOLEAN 54 | END AS res 55 | FROM test 56 | ; 57 | 58 | -- Test a number with out of range value, not a bigint 59 | WITH test AS 60 | ( 61 | SELECT is_bigint('32435463435745636545') AS isbigint 62 | , 0 AS zero 63 | ) 64 | SELECT 65 | CASE 66 | WHEN NOT isbigint THEN 67 | TRUE 68 | ELSE 69 | (1 / zero)::BOOLEAN 70 | END AS res 71 | FROM test 72 | ; 73 | 74 | ROLLBACK; 75 | -------------------------------------------------------------------------------- /test/sql/function_is_bigint_array.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_bigint 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_bigint_array' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test integer array 27 | WITH test AS 28 | ( 29 | SELECT is_bigint_array('{1,2}') AS isbigint_array 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN isbigint_array THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test a with wrong brackets, not a bigint array 43 | WITH test AS 44 | ( 45 | SELECT is_bigint_array('[123,456]') AS isbigint_array 46 | , 0 AS zero 47 | ) 48 | SELECT 49 | CASE 50 | WHEN NOT isbigint_array THEN 51 | TRUE 52 | ELSE 53 | (1 / zero)::BOOLEAN 54 | END AS res 55 | FROM test 56 | ; 57 | 58 | -- Test a number with out of range value, not a bigint array 59 | WITH test AS 60 | ( 61 | SELECT is_bigint_array('{32435463435745636545,1}') AS isbigint_array 62 | , 0 AS zero 63 | ) 64 | SELECT 65 | CASE 66 | WHEN NOT isbigint_array THEN 67 | TRUE 68 | ELSE 69 | (1 / zero)::BOOLEAN 70 | END AS res 71 | FROM test 72 | ; 73 | 74 | ROLLBACK; 75 | -------------------------------------------------------------------------------- /test/sql/function_is_boolean.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_boolean 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_boolean' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test single letters beeing boolean 27 | WITH test AS 28 | ( 29 | SELECT is_boolean('t') AS isboolean_0 30 | , is_boolean('f') AS isboolean_1 31 | , is_boolean('T') AS isboolean_2 32 | , is_boolean('F') AS isboolean_3 33 | , is_boolean('y') AS isboolean_4 34 | , is_boolean('n') AS isboolean_5 35 | , is_boolean('Y') AS isboolean_6 36 | , is_boolean('N') AS isboolean_7 37 | , 0 AS zero 38 | ) 39 | SELECT 40 | CASE 41 | WHEN isboolean_0 AND isboolean_1 AND isboolean_2 AND isboolean_3 AND 42 | isboolean_4 AND isboolean_5 AND isboolean_6 AND isboolean_7 43 | THEN 44 | TRUE 45 | ELSE 46 | (1 / zero)::BOOLEAN 47 | END AS res 48 | FROM test 49 | ; 50 | 51 | -- Test words being boolean 52 | WITH test AS 53 | ( 54 | SELECT is_boolean('TRUE') AS isboolean_0 55 | , is_boolean('FALSE') AS isboolean_1 56 | , is_boolean('true') AS isboolean_2 57 | , is_boolean('false') AS isboolean_3 58 | , is_boolean('YES') AS isboolean_4 59 | , is_boolean('NO') AS isboolean_5 60 | , is_boolean('yes') AS isboolean_6 61 | , is_boolean('no') AS isboolean_7 62 | , 0 AS zero 63 | ) 64 | SELECT 65 | CASE 66 | WHEN isboolean_0 AND isboolean_1 AND isboolean_2 AND isboolean_3 AND 67 | isboolean_4 AND isboolean_5 AND isboolean_6 AND isboolean_7 68 | THEN 69 | TRUE 70 | ELSE 71 | (1 / zero)::BOOLEAN 72 | END AS res 73 | FROM test 74 | ; 75 | 76 | -- Test text for not beeing boolean 77 | WITH test AS 78 | ( 79 | SELECT is_boolean('Not a BOOLEAN') AS isboolean, 0 AS zero 80 | ) 81 | SELECT 82 | CASE 83 | WHEN NOT isboolean THEN 84 | TRUE 85 | ELSE 86 | (1 / zero)::BOOLEAN 87 | END AS res 88 | FROM test 89 | ; 90 | 91 | -- Test positive number for not beeing boolean 92 | WITH test AS 93 | ( 94 | SELECT is_boolean('3') AS isboolean, 0 AS zero 95 | ) 96 | SELECT 97 | CASE 98 | WHEN NOT isboolean THEN 99 | TRUE 100 | ELSE 101 | (1 / zero)::BOOLEAN 102 | END AS res 103 | FROM test 104 | ; 105 | 106 | -- Test negative number for not beeing boolean 107 | WITH test AS 108 | ( 109 | SELECT is_boolean('-1') AS isboolean, 0 AS zero 110 | ) 111 | SELECT 112 | CASE 113 | WHEN NOT isboolean THEN 114 | TRUE 115 | ELSE 116 | (1 / zero)::BOOLEAN 117 | END AS res 118 | FROM test 119 | ; 120 | 121 | ROLLBACK; 122 | -------------------------------------------------------------------------------- /test/sql/function_is_date.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_date 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_date' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 2 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test with date in default format 27 | WITH test AS 28 | ( 29 | SELECT is_date('2018-01-01') AS isdate 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN isdate THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test if all implementations exists 43 | WITH test AS 44 | ( 45 | SELECT COUNT(*) AS exist 46 | FROM pg_catalog.pg_proc 47 | WHERE proname = 'is_date' 48 | ) 49 | SELECT test.exist = 2 AS res 50 | FROM test 51 | ; 52 | 53 | -- Test with wrong date in default format 54 | WITH test AS 55 | ( 56 | SELECT is_date('2018-02-31') AS isdate 57 | , 0 AS zero 58 | ) 59 | SELECT 60 | CASE 61 | WHEN NOT isdate THEN 62 | TRUE 63 | ELSE 64 | (1 / zero)::BOOLEAN 65 | END AS res 66 | FROM test 67 | ; 68 | 69 | -- Test with date in German format 70 | WITH test AS 71 | ( 72 | SELECT is_date('01.01.2018', 'DD.MM.YYYY') AS isdate 73 | , 0 AS zero 74 | ) 75 | SELECT 76 | CASE 77 | WHEN isdate THEN 78 | TRUE 79 | ELSE 80 | (1 / zero)::BOOLEAN 81 | END AS res 82 | FROM test 83 | ; 84 | 85 | -- Test with wrong date in German format 86 | /** 87 | * As there has been a behaviour change in PostgreSQL 10, the result is only 88 | * false with version 10 in <9 it would be true a call to 89 | * SELECT to_date('31.02.2018', 'DD.MM.YYYY')::DATE; 90 | * would return 2018-03-03 91 | */ 92 | WITH test AS 93 | ( 94 | SELECT is_date('31.02.2018', 'DD.MM.YYYY') AS isdate 95 | , 0 AS zero 96 | , current_setting('server_version_num')::INTEGER as version_num 97 | ) 98 | SELECT 99 | CASE 100 | WHEN (version_num >= 100000 AND NOT isdate) OR (version_num < 100000 AND isdate) THEN 101 | TRUE 102 | ELSE 103 | NULL --(1 / zero)::BOOLEAN 104 | END AS res 105 | FROM test 106 | ; 107 | 108 | ROLLBACK; 109 | -------------------------------------------------------------------------------- /test/sql/function_is_double_precision.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_double_precision 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_double_precision' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test integer 27 | WITH test AS 28 | ( 29 | SELECT is_double_precision('123') AS isdoubleprecision 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN isdoubleprecision THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test a number with decimal separator 43 | WITH test AS 44 | ( 45 | SELECT is_double_precision('123.456') AS isdoubleprecision 46 | , 0 AS zero 47 | ) 48 | SELECT 49 | CASE 50 | WHEN isdoubleprecision THEN 51 | TRUE 52 | ELSE 53 | (1 / zero)::BOOLEAN 54 | END AS res 55 | FROM test 56 | ; 57 | 58 | -- Test a number with out of range value, not an integer 59 | WITH test AS 60 | ( 61 | SELECT is_double_precision('123,456') AS isdoubleprecision 62 | , 0 AS zero 63 | ) 64 | SELECT 65 | CASE 66 | WHEN NOT isdoubleprecision THEN 67 | TRUE 68 | ELSE 69 | (1 / zero)::BOOLEAN 70 | END AS res 71 | FROM test 72 | ; 73 | 74 | ROLLBACK; 75 | -------------------------------------------------------------------------------- /test/sql/function_is_empty.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_empty/is_empty_b 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | DO $$ 7 | DECLARE 8 | pg_extension_installed BOOLEAN; 9 | function_source TEXT; 10 | BEGIN 11 | 12 | SELECT count(*) = 1 AS pgcrypto_installed 13 | FROM pg_extension 14 | WHERE extname = 'pgtap' 15 | INTO pg_extension_installed 16 | ; 17 | 18 | IF NOT pg_extension_installed THEN 19 | -- pgtap is not installed, is_empty should be installed 20 | 21 | function_source := 22 | $string$ 23 | -- Test if the function exists 24 | WITH test AS 25 | ( 26 | SELECT COUNT(*) AS exist 27 | , 0 AS zero 28 | FROM pg_catalog.pg_proc 29 | WHERE proname = 'is_empty' 30 | ) 31 | SELECT 32 | CASE 33 | WHEN 1 / test.exist = 1 THEN 34 | TRUE 35 | ELSE 36 | (1 / zero)::BOOLEAN 37 | END AS res 38 | FROM test 39 | ; 40 | ; 41 | $string$ 42 | ; 43 | EXECUTE function_source; 44 | 45 | -- Test not empty 46 | function_source := 47 | $string$ 48 | WITH test AS 49 | ( 50 | SELECT is_empty('abc') AS isempty 51 | , 0 AS zero 52 | ) 53 | SELECT 54 | CASE 55 | WHEN NOT isempty THEN 56 | TRUE 57 | ELSE 58 | (1 / zero)::BOOLEAN 59 | END AS res 60 | FROM test 61 | ; 62 | $string$ 63 | ; 64 | EXECUTE function_source; 65 | 66 | -- Test empty string 67 | function_source := 68 | $string$ 69 | WITH test AS 70 | ( 71 | SELECT is_empty('') AS isempty 72 | , 0 AS zero 73 | ) 74 | SELECT 75 | CASE 76 | WHEN isempty THEN 77 | TRUE 78 | ELSE 79 | (1 / zero)::BOOLEAN 80 | END AS res 81 | FROM test 82 | ; 83 | $string$ 84 | ; 85 | EXECUTE function_source; 86 | 87 | -- Test NULL 88 | function_source := 89 | $string$ 90 | WITH test_data AS 91 | ( 92 | SELECT NULL::TEXT AS test_value 93 | ) 94 | , test AS 95 | ( 96 | SELECT is_empty(test_value) AS isempty 97 | , 0 AS zero 98 | FROM test_data 99 | ) 100 | SELECT 101 | CASE 102 | WHEN isempty THEN 103 | TRUE 104 | ELSE 105 | (1 / zero)::BOOLEAN 106 | END AS res 107 | FROM test 108 | ; 109 | $string$ 110 | ; 111 | EXECUTE function_source; 112 | 113 | ELSE 114 | 115 | -- pgtap is installed, is_empty_b should be installed 116 | function_source := 117 | $string$ 118 | -- Test if the function exists 119 | WITH test AS 120 | ( 121 | SELECT COUNT(*) AS exist 122 | , 0 AS zero 123 | FROM pg_catalog.pg_proc 124 | WHERE proname = 'is_empty_b' 125 | ) 126 | SELECT 127 | CASE 128 | WHEN 1 / test.exist = 1 THEN 129 | TRUE 130 | ELSE 131 | (1 / zero)::BOOLEAN 132 | END AS res 133 | FROM test 134 | ; 135 | ; 136 | $string$ 137 | ; 138 | EXECUTE function_source; 139 | 140 | -- Test not empty 141 | function_source := 142 | $string$ 143 | WITH test AS 144 | ( 145 | SELECT is_empty_b('abc') AS isempty 146 | , 0 AS zero 147 | ) 148 | SELECT 149 | CASE 150 | WHEN NOT isempty THEN 151 | TRUE 152 | ELSE 153 | (1 / zero)::BOOLEAN 154 | END AS res 155 | FROM test 156 | ; 157 | $string$ 158 | ; 159 | EXECUTE function_source; 160 | 161 | -- Test empty string 162 | function_source := 163 | $string$ 164 | WITH test AS 165 | ( 166 | SELECT is_empty_b('') AS isempty 167 | , 0 AS zero 168 | ) 169 | SELECT 170 | CASE 171 | WHEN isempty THEN 172 | TRUE 173 | ELSE 174 | (1 / zero)::BOOLEAN 175 | END AS res 176 | FROM test 177 | $string$ 178 | ; 179 | EXECUTE function_source; 180 | 181 | -- Test NULL 182 | function_source := 183 | $string$ 184 | WITH test_data AS 185 | ( 186 | SELECT NULL::TEXT AS test_value 187 | ) 188 | , test AS 189 | ( 190 | SELECT is_empty_b(test_value) AS isempty 191 | , 0 AS zero 192 | FROM test_data 193 | ) 194 | SELECT 195 | CASE 196 | WHEN isempty THEN 197 | TRUE 198 | ELSE 199 | (1 / zero)::BOOLEAN 200 | END AS res 201 | FROM test 202 | ; 203 | $string$ 204 | ; 205 | EXECUTE function_source; 206 | 207 | END IF; 208 | 209 | END $$; 210 | -------------------------------------------------------------------------------- /test/sql/function_is_encoding.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_encoding 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_encoding' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 2 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test if all implementations exists 27 | WITH test AS 28 | ( 29 | SELECT COUNT(*) AS exist 30 | , 0 AS zero 31 | FROM pg_catalog.pg_proc 32 | WHERE proname = 'is_encoding' 33 | ) 34 | SELECT 35 | CASE 36 | WHEN test.exist = 2 THEN 37 | TRUE 38 | ELSE 39 | (1 / zero)::BOOLEAN 40 | END AS res 41 | FROM test 42 | ; 43 | 44 | -- Test with a test string containing only latin1 45 | WITH test AS 46 | ( 47 | SELECT is_encoding('Some characters', 'LATIN1') AS isencoding 48 | , 0 AS zero 49 | ) 50 | SELECT 51 | CASE 52 | WHEN isencoding THEN 53 | TRUE 54 | ELSE 55 | (1 / zero)::BOOLEAN 56 | END AS res 57 | FROM test 58 | ; 59 | 60 | -- Test with a test string containing non latin1 characters 61 | WITH test AS 62 | ( 63 | SELECT is_encoding('Some characters, ğ is Turkish and not latin1', 'LATIN1') AS isencoding 64 | , 0 AS zero 65 | ) 66 | SELECT 67 | CASE 68 | WHEN NOT isencoding THEN 69 | TRUE 70 | ELSE 71 | (1 / zero)::BOOLEAN 72 | END AS res 73 | FROM test 74 | ; 75 | 76 | -- Test with a test string containing only latin1 77 | WITH test AS 78 | ( 79 | SELECT is_encoding('Some characters', 'LATIN1', 'UTF8') AS isencoding 80 | , 0 AS zero 81 | ) 82 | SELECT 83 | CASE 84 | WHEN isencoding THEN 85 | TRUE 86 | ELSE 87 | (1 / zero)::BOOLEAN 88 | END AS res 89 | FROM test 90 | ; 91 | 92 | -- Test with a test string containing non latin1 characters 93 | WITH test AS 94 | ( 95 | SELECT is_encoding('Some characters, ğ is Turkish and not latin1', 'LATIN1', 'UTF8') AS isencoding 96 | , 0 AS zero 97 | ) 98 | SELECT 99 | CASE 100 | WHEN NOT isencoding THEN 101 | TRUE 102 | ELSE 103 | (1 / zero)::BOOLEAN 104 | END AS res 105 | FROM test 106 | ; 107 | 108 | ROLLBACK; 109 | -------------------------------------------------------------------------------- /test/sql/function_is_hex.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_hex 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_hex' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test hexadicimal number 27 | WITH test AS 28 | ( 29 | SELECT is_hex('a1b0') AS ishex 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN ishex THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test a non hexadeciaml number 43 | WITH test AS 44 | ( 45 | SELECT is_hex('a1b0w') AS ishex 46 | , 0 AS zero 47 | ) 48 | SELECT 49 | CASE 50 | WHEN NOT ishex THEN 51 | TRUE 52 | ELSE 53 | (1 / zero)::BOOLEAN 54 | END AS res 55 | FROM test 56 | ; 57 | 58 | -- Test a hexadeciaml number, that is to big for BIGINT 59 | WITH test AS 60 | ( 61 | SELECT is_hex('a1b0c3c3c3c4b5d3') AS ishex 62 | , 0 AS zero 63 | ) 64 | SELECT 65 | CASE 66 | WHEN NOT ishex THEN 67 | TRUE 68 | ELSE 69 | (1 / zero)::BOOLEAN 70 | END AS res 71 | FROM test 72 | ; 73 | 74 | ROLLBACK; 75 | -------------------------------------------------------------------------------- /test/sql/function_is_integer.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_integer 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_integer' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test integer 27 | WITH test AS 28 | ( 29 | SELECT is_integer('123') AS isinteger 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN isinteger THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test a number with decimal separator, not an integer 43 | WITH test AS 44 | ( 45 | SELECT is_integer('123.456') AS isinteger 46 | , 0 AS zero 47 | ) 48 | SELECT 49 | CASE 50 | WHEN NOT isinteger THEN 51 | TRUE 52 | ELSE 53 | (1 / zero)::BOOLEAN 54 | END AS res 55 | FROM test 56 | ; 57 | 58 | -- Test a number with out of range value, not an integer 59 | WITH test AS 60 | ( 61 | SELECT is_integer('3243546343') AS isinteger 62 | , 0 AS zero 63 | ) 64 | SELECT 65 | CASE 66 | WHEN NOT isinteger THEN 67 | TRUE 68 | ELSE 69 | (1 / zero)::BOOLEAN 70 | END AS res 71 | FROM test 72 | ; 73 | 74 | ROLLBACK; 75 | -------------------------------------------------------------------------------- /test/sql/function_is_integer_array.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_integer_array 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_integer_array' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test integer array 27 | WITH test AS 28 | ( 29 | SELECT is_integer_array('{1,2,3}') AS isinteger_array 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN isinteger_array THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test a with wrong brackets, not an integer array 43 | WITH test AS 44 | ( 45 | SELECT is_integer_array('[123,456]') AS isinteger_array 46 | , 0 AS zero 47 | ) 48 | SELECT 49 | CASE 50 | WHEN NOT isinteger_array THEN 51 | TRUE 52 | ELSE 53 | (1 / zero)::BOOLEAN 54 | END AS res 55 | FROM test 56 | ; 57 | 58 | -- Test a number with out of range value, not an integer array 59 | WITH test AS 60 | ( 61 | SELECT is_integer_array('{3243546343,789879}') AS isinteger_array 62 | , 0 AS zero 63 | ) 64 | SELECT 65 | CASE 66 | WHEN NOT isinteger_array THEN 67 | TRUE 68 | ELSE 69 | (1 / zero)::BOOLEAN 70 | END AS res 71 | FROM test 72 | ; 73 | 74 | ROLLBACK; 75 | -------------------------------------------------------------------------------- /test/sql/function_is_json.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_json 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_json' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test with a test string containing no JSON 27 | WITH test AS 28 | ( 29 | SELECT is_json('Not a JSON') AS isjson 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN NOT isjson THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test with a test string containing JSON 43 | WITH test AS 44 | ( 45 | SELECT is_json('{"review": {"date": "1970-12-30", "votes": 10, "rating": 5, "helpful_votes": 0}, "product": {"id": "1551803542", "group": "Book", "title": "Start and Run a Coffee Bar (Start & Run a)", "category": "Business & Investing", "sales_rank": 11611, "similar_ids": ["0471136174", "0910627312", "047112138X", "0786883561", "0201570483"], "subcategory": "General"}, "customer_id": "AE22YDHSBFYIP"}') AS isjson 46 | , 0 AS zero 47 | ) 48 | SELECT 49 | CASE 50 | WHEN isjson THEN 51 | TRUE 52 | ELSE 53 | (1 / zero)::BOOLEAN 54 | END AS res 55 | FROM test 56 | ; 57 | 58 | ROLLBACK; 59 | -------------------------------------------------------------------------------- /test/sql/function_is_jsonb.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_jsonb 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_jsonb' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test with a test string containing no JSON 27 | WITH test AS 28 | ( 29 | SELECT is_jsonb('Not a JSONB') AS isjsonb 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN NOT isjsonb THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test with a test string containing JSON 43 | WITH test AS 44 | ( 45 | SELECT is_jsonb('{"review": {"date": "1970-12-30", "votes": 10, "rating": 5, "helpful_votes": 0}, "product": {"id": "1551803542", "group": "Book", "title": "Start and Run a Coffee Bar (Start & Run a)", "category": "Business & Investing", "sales_rank": 11611, "similar_ids": ["0471136174", "0910627312", "047112138X", "0786883561", "0201570483"], "subcategory": "General"}, "customer_id": "AE22YDHSBFYIP"}') AS isjsonb 46 | , 0 AS zero 47 | ) 48 | SELECT 49 | CASE 50 | WHEN isjsonb THEN 51 | TRUE 52 | ELSE 53 | (1 / zero)::BOOLEAN 54 | END AS res 55 | FROM test 56 | ; 57 | 58 | ROLLBACK; 59 | -------------------------------------------------------------------------------- /test/sql/function_is_latin1.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_latin1 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_latin1' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test with a test string containing only latin1 27 | WITH test AS 28 | ( 29 | SELECT is_latin1('Some characters') AS islatin1 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN islatin1 THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test with a test string containing non latin1 characters 43 | WITH test AS 44 | ( 45 | SELECT is_latin1('Some characters, ğ is Turkish and not latin1') AS islatin1 46 | , 0 AS zero 47 | ) 48 | SELECT 49 | CASE 50 | WHEN NOT islatin1 THEN 51 | TRUE 52 | ELSE 53 | (1 / zero)::BOOLEAN 54 | END AS res 55 | FROM test 56 | ; 57 | 58 | ROLLBACK; 59 | -------------------------------------------------------------------------------- /test/sql/function_is_numeric.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_numeric 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_numeric' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test integer 27 | WITH test AS 28 | ( 29 | SELECT is_numeric('123') AS isnumeric 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN isnumeric THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test a number with decimal separator 43 | WITH test AS 44 | ( 45 | SELECT is_numeric('123.456') AS isnumeric 46 | , 0 AS zero 47 | ) 48 | SELECT 49 | CASE 50 | WHEN isnumeric THEN 51 | TRUE 52 | ELSE 53 | (1 / zero)::BOOLEAN 54 | END AS res 55 | FROM test 56 | ; 57 | 58 | -- Test not a number 59 | WITH test AS 60 | ( 61 | SELECT is_numeric('1 2') AS isnumeric 62 | , 0 AS zero 63 | ) 64 | SELECT 65 | CASE 66 | WHEN NOT isnumeric THEN 67 | TRUE 68 | ELSE 69 | (1 / zero)::BOOLEAN 70 | END AS res 71 | FROM test 72 | ; 73 | 74 | ROLLBACK; 75 | -------------------------------------------------------------------------------- /test/sql/function_is_real.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_real 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_real' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test integer 27 | WITH test AS 28 | ( 29 | SELECT is_real('123') AS isreal 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN isreal THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test a number with decimal separator 43 | WITH test AS 44 | ( 45 | SELECT is_real('123.456') AS isreal 46 | , 0 AS zero 47 | ) 48 | SELECT 49 | CASE 50 | WHEN isreal THEN 51 | TRUE 52 | ELSE 53 | (1 / zero)::BOOLEAN 54 | END AS res 55 | FROM test 56 | ; 57 | 58 | -- Test a number with out of range value, not an integer 59 | WITH test AS 60 | ( 61 | SELECT is_real('123,456') AS isreal 62 | , 0 AS zero 63 | ) 64 | SELECT 65 | CASE 66 | WHEN NOT isreal THEN 67 | TRUE 68 | ELSE 69 | (1 / zero)::BOOLEAN 70 | END AS res 71 | FROM test 72 | ; 73 | 74 | ROLLBACK; 75 | -------------------------------------------------------------------------------- /test/sql/function_is_smallint.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_smallint 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_smallint' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test integer 27 | WITH test AS 28 | ( 29 | SELECT is_smallint('123') AS issmallint 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN issmallint THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test a number with decimal separator, not a smallint 43 | WITH test AS 44 | ( 45 | SELECT is_smallint('123.456') AS issmallint 46 | , 0 AS zero 47 | ) 48 | SELECT 49 | CASE 50 | WHEN NOT issmallint THEN 51 | TRUE 52 | ELSE 53 | (1 / zero)::BOOLEAN 54 | END AS res 55 | FROM test 56 | ; 57 | 58 | -- Test a number with out of range value, not a smallint 59 | WITH test AS 60 | ( 61 | SELECT is_smallint('3243546343') AS issmallint 62 | , 0 AS zero 63 | ) 64 | SELECT 65 | CASE 66 | WHEN NOT issmallint THEN 67 | TRUE 68 | ELSE 69 | (1 / zero)::BOOLEAN 70 | END AS res 71 | FROM test 72 | ; 73 | 74 | ROLLBACK; 75 | -------------------------------------------------------------------------------- /test/sql/function_is_smallint_array.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_smallint_array 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_smallint_array' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test smallint array 27 | WITH test AS 28 | ( 29 | SELECT is_smallint_array('{1,2,3}') AS issmallint_array 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN issmallint_array THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test a with wrong brackets, not an integer array 43 | WITH test AS 44 | ( 45 | SELECT is_smallint_array('[123,456]') AS issmallint_array 46 | , 0 AS zero 47 | ) 48 | SELECT 49 | CASE 50 | WHEN NOT issmallint_array THEN 51 | TRUE 52 | ELSE 53 | (1 / zero)::BOOLEAN 54 | END AS res 55 | FROM test 56 | ; 57 | 58 | -- Test a number with out of range value, not an integer array 59 | WITH test AS 60 | ( 61 | SELECT is_smallint_array('{3243546343,789879}') AS issmallint_array 62 | , 0 AS zero 63 | ) 64 | SELECT 65 | CASE 66 | WHEN NOT issmallint_array THEN 67 | TRUE 68 | ELSE 69 | (1 / zero)::BOOLEAN 70 | END AS res 71 | FROM test 72 | ; 73 | 74 | ROLLBACK; 75 | -------------------------------------------------------------------------------- /test/sql/function_is_text_array.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_text_array 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_text_array' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test text array 27 | WITH test AS 28 | ( 29 | SELECT is_text_array('{a,b,c}') AS istext_array 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN istext_array THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test a with wrong brackets, not an integer array 43 | WITH test AS 44 | ( 45 | SELECT is_text_array('[123,456]') AS istext_array 46 | , 0 AS zero 47 | ) 48 | SELECT 49 | CASE 50 | WHEN NOT istext_array THEN 51 | TRUE 52 | ELSE 53 | (1 / zero)::BOOLEAN 54 | END AS res 55 | FROM test 56 | ; 57 | 58 | -- Test a number, an integer array 59 | WITH test AS 60 | ( 61 | SELECT is_text_array('{3243546343,789879}') AS istext_array 62 | , 0 AS zero 63 | ) 64 | SELECT 65 | CASE 66 | WHEN istext_array THEN 67 | TRUE 68 | ELSE 69 | (1 / zero)::BOOLEAN 70 | END AS res 71 | FROM test 72 | ; 73 | 74 | ROLLBACK; 75 | -------------------------------------------------------------------------------- /test/sql/function_is_time.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_time 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_time' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 2 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test if all implementations exists 27 | WITH test AS 28 | ( 29 | SELECT COUNT(*) AS exist 30 | , 0 AS zero 31 | FROM pg_catalog.pg_proc 32 | WHERE proname = 'is_time' 33 | ) 34 | SELECT test.exist = 2 AS res 35 | FROM test 36 | ; 37 | 38 | -- Test with time in default format 39 | WITH test AS 40 | ( 41 | SELECT is_time('14:33:55.456574') AS istime 42 | , 0 AS zero 43 | ) 44 | SELECT 45 | CASE 46 | WHEN istime THEN 47 | TRUE 48 | ELSE 49 | (1 / zero)::BOOLEAN 50 | END AS res 51 | FROM test 52 | ; 53 | 54 | -- Test with wrong time in default format 55 | WITH test AS 56 | ( 57 | SELECT is_time('25:33:55.456574') AS istime 58 | , 0 AS zero 59 | ) 60 | SELECT 61 | CASE 62 | WHEN NOT istime THEN 63 | TRUE 64 | ELSE 65 | (1 / zero)::BOOLEAN 66 | END AS res 67 | FROM test 68 | ; 69 | 70 | -- Test with time in some format 71 | WITH test AS 72 | ( 73 | SELECT is_time('14.33.55,456574', 'HH24.MI.SS,US') AS istime 74 | , 0 AS zero 75 | ) 76 | SELECT 77 | CASE 78 | WHEN istime THEN 79 | TRUE 80 | ELSE 81 | (1 / zero)::BOOLEAN 82 | END AS res 83 | FROM test 84 | ; 85 | 86 | -- Test with wrong time in some format 87 | /** 88 | * As there has been a behaviour change in PostgreSQL 10, the result is only 89 | * false with version 10 in <9 it would be true a call to 90 | * SELECT to_timestamp('25:33:55.456574', 'HH24.MI.SS,US')::TIME; 91 | * would return 01:33:55.456574 92 | */ 93 | WITH t1 AS 94 | ( 95 | SELECT is_time('25.33.55,456574', 'HH24.MI.SS,US') AS istime 96 | , current_setting('server_version_num')::INTEGER as version_num 97 | ) 98 | , test AS 99 | ( 100 | SELECT 101 | CASE 102 | WHEN (NOT istime AND version_num >= 100000) OR (istime AND version_num < 100000) THEN 103 | 1 104 | ELSE 105 | 0 106 | END AS res 107 | FROM t1 108 | ) 109 | SELECT (1 / res)::BOOLEAN AS res 110 | FROM test 111 | ; 112 | 113 | WITH t1 AS 114 | ( 115 | SELECT is_time('25.33.55,456574', 'HH24.MI.SS,US') AS istime 116 | , current_setting('server_version_num')::INTEGER as version_num 117 | ) 118 | , test AS 119 | ( 120 | SELECT 121 | CASE 122 | WHEN (NOT istime AND version_num >= 100000) OR (istime AND version_num < 100000) THEN 123 | 1 124 | ELSE 125 | 0 126 | END AS res 127 | FROM t1 128 | ) 129 | SELECT (1 / res)::BOOLEAN AS res 130 | FROM test 131 | ; 132 | 133 | ROLLBACK; 134 | -------------------------------------------------------------------------------- /test/sql/function_is_timestamp.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_timestamp 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_timestamp' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 2 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test if all implementations exists 27 | WITH test AS 28 | ( 29 | SELECT COUNT(*) AS exist 30 | , 0 AS zero 31 | FROM pg_catalog.pg_proc 32 | WHERE proname = 'is_timestamp' 33 | ) 34 | SELECT 35 | CASE 36 | WHEN test.exist = 2 THEN 37 | TRUE 38 | ELSE 39 | (1 / zero)::BOOLEAN 40 | END AS res 41 | FROM test 42 | ; 43 | 44 | -- Test with timestamp in default format 45 | WITH test AS 46 | ( 47 | SELECT is_timestamp('2018-01-01 00:00:00') AS istimestamp 48 | , 0 AS zero 49 | ) 50 | SELECT 51 | CASE 52 | WHEN istimestamp THEN 53 | TRUE 54 | ELSE 55 | (1 / zero)::BOOLEAN 56 | END AS res 57 | FROM test 58 | ; 59 | 60 | -- Test with wrong timestamp in default format 61 | WITH test AS 62 | ( 63 | SELECT is_timestamp('2018-01-01 25:00:00') AS istimestamp 64 | , 0 AS zero 65 | ) 66 | SELECT 67 | CASE 68 | WHEN NOT istimestamp THEN 69 | TRUE 70 | ELSE 71 | (1 / zero)::BOOLEAN 72 | END AS res 73 | FROM test 74 | ; 75 | 76 | -- Test with timestamp in German format 77 | WITH test AS 78 | ( 79 | SELECT is_timestamp('01.01.2018 00:00:00', 'DD.MM.YYYY HH24.MI.SS') AS istimestamp 80 | , 0 AS zero 81 | ) 82 | SELECT 83 | CASE 84 | WHEN istimestamp THEN 85 | TRUE 86 | ELSE 87 | (1 / zero)::BOOLEAN 88 | END AS res 89 | FROM test 90 | ; 91 | 92 | -- Test with wrong timestamp in German format 93 | /** 94 | * As there has been a behaviour change in PostgreSQL 10, the result is only 95 | * false with version 10 in <9 it would be true a call to 96 | * SELECT to_timestamp('01.01.2018 25:00:00', 'DD.MM.YYYY HH24.MI.SS')::TIMESTAMP; 97 | * would return 2018-01-02 01:00:00 98 | */ 99 | WITH test AS 100 | ( 101 | SELECT is_timestamp('01.01.2018 25:00:00', 'DD.MM.YYYY HH24.MI.SS') AS istimestamp 102 | , 0 AS zero 103 | , current_setting('server_version_num')::INTEGER as version_num 104 | ) 105 | SELECT 106 | CASE 107 | WHEN version_num >= 100000 THEN 108 | CASE 109 | WHEN NOT istimestamp THEN 110 | TRUE 111 | ELSE 112 | (1 / zero)::BOOLEAN 113 | END 114 | /* 115 | ELSE 116 | CASE 117 | WHEN istimestamp THEN 118 | TRUE 119 | ELSE 120 | (1 / zero)::BOOLEAN 121 | END 122 | */ 123 | END AS res 124 | FROM test 125 | ; 126 | WITH test AS 127 | ( 128 | SELECT is_timestamp('01.01.2018 25:00:00', 'DD.MM.YYYY HH24.MI.SS') AS istimestamp 129 | , 0 AS zero 130 | , current_setting('server_version_num')::INTEGER as version_num 131 | ) 132 | SELECT 133 | CASE 134 | WHEN version_num < 100000 THEN 135 | CASE 136 | WHEN istimestamp THEN 137 | TRUE 138 | ELSE 139 | NULL--(1 / zero)::BOOLEAN 140 | END 141 | END AS res 142 | FROM test 143 | ; 144 | 145 | 146 | 147 | ROLLBACK; 148 | -------------------------------------------------------------------------------- /test/sql/function_is_uuid.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function is_uuid 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'is_uuid' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test uuid 27 | WITH test AS 28 | ( 29 | SELECT is_uuid('1eb2f229-e013-4e5a-9f51-15a81c820155') AS isuuid 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN isuuid THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test a number with out of range value, not a uuid 43 | WITH test AS 44 | ( 45 | SELECT is_smallint('3243546343') AS isuuid 46 | , 0 AS zero 47 | ) 48 | SELECT 49 | CASE 50 | WHEN NOT isuuid THEN 51 | TRUE 52 | ELSE 53 | (1 / zero)::BOOLEAN 54 | END AS res 55 | FROM test 56 | ; 57 | 58 | ROLLBACK; 59 | -------------------------------------------------------------------------------- /test/sql/function_pg_schema_size.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function pg_schema_size 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'pg_schema_size' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Prevent no result because of an empty database without any tables 27 | -- Create at table 28 | CREATE TABLE test_pg_schema_size(id INTEGER, some_value text); 29 | 30 | -- Insert some data 31 | INSERT INTO test_pg_schema_size(id, some_value) VALUES 32 | (1, 'value 1'), 33 | (1, NULL), 34 | (2, 'value 2'), 35 | (2, NULL), 36 | (2, NULL), 37 | (3, 'value 3') 38 | ; 39 | 40 | 41 | -- Test with date in default format 42 | WITH test AS 43 | ( 44 | SELECT pg_schema_size('public') AS schema_size 45 | , 0 AS zero 46 | ) 47 | SELECT 48 | CASE 49 | WHEN schema_size > 0 THEN 50 | TRUE 51 | ELSE 52 | (1 / zero)::BOOLEAN 53 | END AS res 54 | FROM test 55 | ; 56 | 57 | ROLLBACK; 58 | -------------------------------------------------------------------------------- /test/sql/function_replace_encoding.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for the functions replace_encoding 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT count(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'replace_encoding' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 3 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test if all three implementations exists 27 | WITH test AS 28 | ( 29 | SELECT count(*) AS exist 30 | , 0 AS zero 31 | FROM pg_catalog.pg_proc 32 | WHERE proname = 'replace_encoding' 33 | ) 34 | SELECT 35 | CASE 36 | WHEN test.exist = 3 THEN 37 | TRUE 38 | ELSE 39 | (1 / test.zero)::BOOLEAN 40 | END AS res 41 | FROM test 42 | ; 43 | 44 | -- Test of the first implementation which replaces none latin1 characters with 45 | -- empty strings 46 | WITH test AS 47 | ( 48 | SELECT 'ağbƵcğeƵ'::TEXT AS test_string 49 | , 'latin1'::TEXT AS enc 50 | , 0 AS zero 51 | ) 52 | SELECT 53 | CASE 54 | WHEN length(test_string) = 8 AND length(replace_encoding(test_string, enc)) = 4 THEN 55 | TRUE 56 | ELSE 57 | (1 / test.zero)::BOOLEAN 58 | END AS res_1 59 | , CASE 60 | WHEN is_encoding(replace_encoding(test_string, enc), enc) THEN 61 | TRUE 62 | ELSE 63 | (1 / test.zero)::BOOLEAN 64 | END AS res_2 65 | FROM test 66 | ; 67 | 68 | -- Test of the second implementation which replaces none latin1 characters with 69 | -- second parameter 70 | WITH test AS 71 | ( 72 | SELECT 'ağbcğe'::TEXT AS test_string 73 | , 'latin1'::TEXT AS enc 74 | , 'g'::TEXT AS replacement 75 | , 0 AS zero 76 | ) 77 | SELECT 78 | CASE 79 | WHEN length(test_string) = length(replace_encoding(test_string, enc, replacement)) THEN 80 | TRUE 81 | ELSE 82 | (1 / test.zero)::BOOLEAN 83 | END AS res_1 84 | , CASE 85 | WHEN is_encoding(replace_encoding(test_string, enc, replacement), enc) THEN 86 | TRUE 87 | ELSE 88 | (1 / test.zero)::BOOLEAN 89 | END AS res_2 90 | FROM test 91 | ; 92 | 93 | -- Test of the third implementation which replaces given none latin1 characters 94 | -- in an array as second parameter with latin1 characters given in an array as 95 | -- the third paramater 96 | WITH test AS 97 | ( 98 | SELECT 'ağbƵcğeƵ'::TEXT AS test_string 99 | , string_to_array('ğ,Ƶ'::TEXT, ',') AS to_replace 100 | , string_to_array('g,Z'::TEXT, ',') AS replacement 101 | , 0 AS zero 102 | ) 103 | SELECT 104 | CASE 105 | WHEN length(test_string) = length(replace_encoding(test_string, to_replace, replacement)) THEN 106 | TRUE 107 | ELSE 108 | (1 / test.zero)::BOOLEAN 109 | END AS res_1 110 | , CASE 111 | WHEN is_latin1(replace_encoding(test_string, to_replace, replacement)) THEN 112 | TRUE 113 | ELSE 114 | (1 / test.zero)::BOOLEAN 115 | END AS res_2 116 | FROM test 117 | ; 118 | 119 | ROLLBACK; 120 | -------------------------------------------------------------------------------- /test/sql/function_replace_latin1.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for the functions replace_latin1 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT count(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'replace_latin1' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 3 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / test.zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test if all three implementations exists 27 | WITH test AS 28 | ( 29 | SELECT count(*) AS exist 30 | , 0 AS zero 31 | FROM pg_catalog.pg_proc 32 | WHERE proname = 'replace_latin1' 33 | ) 34 | SELECT 35 | CASE 36 | WHEN test.exist = 3 THEN 37 | TRUE 38 | ELSE 39 | (1 / test.zero)::BOOLEAN 40 | END AS res 41 | FROM test 42 | ; 43 | 44 | -- Test of the first implementation which replaces none latin1 characters with 45 | -- empty strings 46 | WITH test AS 47 | ( 48 | SELECT 'ağbƵcğeƵ'::TEXT AS test_string 49 | , 0 AS zero 50 | ) 51 | SELECT 52 | CASE 53 | WHEN length(test_string) = 8 AND length(replace_latin1(test_string)) = 4 THEN 54 | TRUE 55 | ELSE 56 | (1 / test.zero)::BOOLEAN 57 | END AS res_1 58 | , CASE 59 | WHEN is_latin1(replace_latin1(test_string)) THEN 60 | TRUE 61 | ELSE 62 | (1 / test.zero)::BOOLEAN 63 | END AS res_2 64 | FROM test 65 | ; 66 | 67 | -- Test of the second implementation which replaces none latin1 characters with 68 | -- second parameter 69 | WITH test AS 70 | ( 71 | SELECT 'ağbcğe'::TEXT AS test_string 72 | , 'g'::TEXT AS replacement 73 | , 0 AS zero 74 | ) 75 | SELECT 76 | CASE 77 | WHEN length(test_string) = length(replace_latin1(test_string, replacement)) THEN 78 | TRUE 79 | ELSE 80 | (1 / test.zero)::BOOLEAN 81 | END AS res_1 82 | , CASE 83 | WHEN is_latin1(replace_latin1(test_string, replacement)) THEN 84 | TRUE 85 | ELSE 86 | (1 / test.zero)::BOOLEAN 87 | END AS res_2 88 | FROM test 89 | ; 90 | 91 | -- Test of the third implementation which replaces given none latin1 characters 92 | -- in an array as second parameter with latin1 characters given in an array as 93 | -- the third paramater 94 | WITH test AS 95 | ( 96 | SELECT 'ağbƵcğeƵ'::TEXT AS test_string 97 | , string_to_array('ğ,Ƶ'::TEXT, ',') AS to_replace 98 | , string_to_array('g,Z'::TEXT, ',') AS replacement 99 | , 0 AS zero 100 | ) 101 | SELECT 102 | CASE 103 | WHEN length(test_string) = length(replace_latin1(test_string, to_replace, replacement)) THEN 104 | TRUE 105 | ELSE 106 | (1 / test.zero)::BOOLEAN 107 | END AS res_1 108 | , CASE 109 | WHEN is_latin1(replace_latin1(test_string, to_replace, replacement)) THEN 110 | TRUE 111 | ELSE 112 | (1 / test.zero)::BOOLEAN 113 | END AS res_2 114 | FROM test 115 | ; 116 | 117 | ROLLBACK; 118 | -------------------------------------------------------------------------------- /test/sql/function_return_not_part_of_encoding.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for the functions return_not_part_of_encoding 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT count(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'return_not_part_of_encoding' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / test.zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test the returning result which should contain two array elements 27 | WITH test AS 28 | ( 29 | SELECT return_not_part_of_encoding('ağbƵcğeƵ', 'latin1') AS res 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN array_length(res, 1) = 2 THEN 35 | TRUE 36 | ELSE 37 | (1 / test.zero)::BOOLEAN 38 | END as res_1 39 | , CASE 40 | WHEN 'ğ' = ANY (res) AND 'Ƶ' = ANY (res) THEN 41 | TRUE 42 | ELSE 43 | (1 / test.zero)::BOOLEAN 44 | END as res_2 45 | FROM test 46 | ; 47 | 48 | ROLLBACK; 49 | -------------------------------------------------------------------------------- /test/sql/function_return_not_part_of_latin1.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for the functions return_not_part_of_latin1 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT count(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'return_not_part_of_latin1' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / test.zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test the returning result which should contain two array elements 27 | with test AS 28 | ( 29 | SELECT return_not_part_of_latin1('ağbƵcğeƵ') AS res 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN array_length(res, 1) = 2 THEN 35 | TRUE 36 | ELSE 37 | (1 / test.zero)::BOOLEAN 38 | END as res_1 39 | , CASE 40 | WHEN 'ğ' = ANY (res) AND 'Ƶ' = ANY (res) THEN 41 | TRUE 42 | ELSE 43 | (1 / test.zero)::BOOLEAN 44 | END as res_2 45 | FROM test 46 | ; 47 | 48 | ROLLBACK; 49 | -------------------------------------------------------------------------------- /test/sql/function_sha256.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function sha256 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | DO $$ 7 | DECLARE 8 | pg_extension_installed BOOLEAN; 9 | BEGIN 10 | 11 | SELECT count(*) = 1 AS pgcrypto_installed FROM pg_extension WHERE extname = 'pgcrypto' INTO pg_extension_installed; 12 | 13 | IF pg_extension_installed THEN 14 | -- The pgcrypto extension is installed, sha256 should be installed, that will be tested 15 | WITH test AS 16 | ( 17 | SELECT COUNT(*) AS exist 18 | , 0 AS zero 19 | FROM pg_catalog.pg_proc 20 | WHERE proname = 'sha256' 21 | ) 22 | SELECT 23 | CASE 24 | WHEN 1 / test.exist = 1 THEN 25 | TRUE 26 | ELSE 27 | (1 / zero)::BOOLEAN 28 | END AS res 29 | FROM test 30 | ; 31 | 32 | -- Test with a test string 33 | WITH test AS 34 | ( 35 | SELECT sha256('test-string'::bytea) AS hashed, 'test-string'::bytea AS test_case, 0 AS zero 36 | ) 37 | SELECT 38 | CASE 39 | WHEN hashed = ENCODE(digest(test_case, 'sha256'), 'hex') THEN 40 | TRUE 41 | ELSE 42 | (1 / zero)::BOOLEAN 43 | END AS res 44 | FROM test 45 | ; 46 | 47 | END IF; 48 | 49 | END $$; 50 | -------------------------------------------------------------------------------- /test/sql/function_to_unix_timestamp.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for functions to_unix_timestamp 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'to_unix_timestamp' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 2 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / test.zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test with timestamp without time zone 27 | WITH test AS 28 | ( 29 | SELECT to_unix_timestamp('2018-01-01 00:00:00') AS unix_timestamp 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN unix_timestamp > 0 THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | -- Test with timestamp with time zone 43 | WITH t1 AS 44 | ( 45 | SELECT to_unix_timestamp(now()) AS unix_timestamp 46 | ) 47 | , test AS 48 | ( 49 | SELECT 50 | CASE 51 | WHEN unix_timestamp > 0 THEN 52 | 1 53 | ELSE 54 | 0 55 | END AS res 56 | FROM t1 57 | ) 58 | SELECT (1 / res)::BOOLEAN AS res 59 | FROM test 60 | ; 61 | 62 | ROLLBACK; 63 | -------------------------------------------------------------------------------- /test/sql/get_markdown_doku_by_schema.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for function get_markdown_doku_by_schema 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | DO $$ 7 | BEGIN 8 | 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_proc 14 | WHERE proname = 'get_markdown_doku_by_schema' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN test.exist > 0 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test Markdown generaton for the current schema 27 | WITH test AS 28 | ( 29 | SELECT get_markdown_doku_by_schema(current_schema) AS markdown 30 | , 0 AS zero 31 | ) 32 | SELECT 33 | CASE 34 | WHEN length(markdown) > 0 THEN 35 | TRUE 36 | ELSE 37 | (1 / zero)::BOOLEAN 38 | END AS res 39 | FROM test 40 | ; 41 | 42 | END $$; 43 | -------------------------------------------------------------------------------- /test/sql/view_pg_active_locks.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for view pg_active_locks 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the view exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_views 14 | WHERE viewname = 'pg_active_locks' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test if the view runs without errors 27 | WITH test AS 28 | ( 29 | SELECT count(*) as key_count 30 | , 0 AS zero 31 | FROM pg_active_locks 32 | ) 33 | SELECT 34 | CASE 35 | WHEN key_count >= 0 THEN 36 | TRUE 37 | ELSE 38 | (1 / zero)::BOOLEAN 39 | END AS res 40 | FROM test 41 | ; 42 | 43 | ROLLBACK; 44 | -------------------------------------------------------------------------------- /test/sql/view_pg_bloat_info.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for view pg_bloat_info 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_views 14 | WHERE viewname = 'pg_bloat_info' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test if the view runs without errors 27 | WITH test AS 28 | ( 29 | SELECT count(*) as key_count 30 | , 0 AS zero 31 | FROM pg_db_views 32 | ) 33 | SELECT 34 | CASE 35 | WHEN key_count >= 0 THEN 36 | TRUE 37 | ELSE 38 | (1 / zero)::BOOLEAN 39 | END AS res 40 | FROM test 41 | ; 42 | 43 | ROLLBACK; 44 | -------------------------------------------------------------------------------- /test/sql/view_pg_db_views.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for view pg_db_views 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_views 14 | WHERE viewname = 'pg_db_views' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test if the view runs without errors 27 | WITH test AS 28 | ( 29 | SELECT count(*) as key_count 30 | , 0 AS zero 31 | FROM pg_db_views 32 | ) 33 | SELECT 34 | CASE 35 | WHEN key_count >= 0 THEN 36 | TRUE 37 | ELSE 38 | (1 / zero)::BOOLEAN 39 | END AS res 40 | FROM test 41 | ; 42 | 43 | ROLLBACK; 44 | -------------------------------------------------------------------------------- /test/sql/view_pg_foreign_keys.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for view pg_foreign_keys 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_views 14 | WHERE viewname = 'pg_foreign_keys' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test if the view runs without errors 27 | WITH test AS 28 | ( 29 | SELECT count(*) as key_count 30 | , 0 AS zero 31 | FROM pg_foreign_keys 32 | ) 33 | SELECT 34 | CASE 35 | WHEN key_count >= 0 THEN 36 | TRUE 37 | ELSE 38 | (1 / zero)::BOOLEAN 39 | END AS res 40 | FROM test 41 | ; 42 | 43 | ROLLBACK; 44 | -------------------------------------------------------------------------------- /test/sql/view_pg_functions.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for view pg_functions 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | DO $$ 7 | DECLARE 8 | version_greater_11 BOOLEAN; 9 | res BOOLEAN; 10 | BEGIN 11 | SELECT to_number((string_to_array(version(), ' '))[2], '999.99') >= 11 INTO version_greater_11; 12 | 13 | IF version_greater_11 THEN 14 | -- Test if the function exists 15 | WITH test AS 16 | ( 17 | SELECT COUNT(*) AS exist 18 | , 0 AS zero 19 | FROM pg_catalog.pg_views 20 | WHERE viewname = 'pg_functions' 21 | ) 22 | SELECT 23 | CASE 24 | WHEN 1 / test.exist = 1 THEN 25 | TRUE 26 | ELSE 27 | (1 / zero)::BOOLEAN 28 | END AS res 29 | FROM test 30 | INTO res 31 | ; 32 | 33 | -- Test if the view runs without errors 34 | WITH test AS 35 | ( 36 | SELECT count(*) as key_count 37 | , 0 AS zero 38 | FROM pg_functions 39 | ) 40 | SELECT 41 | CASE 42 | WHEN key_count >= 0 THEN 43 | TRUE 44 | ELSE 45 | (1 / zero)::BOOLEAN 46 | END AS res 47 | FROM test 48 | INTO res 49 | ; 50 | 51 | ROLLBACK; 52 | END IF; 53 | 54 | END $$; 55 | -------------------------------------------------------------------------------- /test/sql/view_pg_object_ownership.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for view pg_object_ownership 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | WITH test AS 8 | ( 9 | SELECT COUNT(*) AS exist 10 | , 0 AS zero 11 | FROM pg_catalog.pg_views 12 | WHERE viewname = 'pg_object_ownership' 13 | ) 14 | SELECT 15 | CASE 16 | WHEN 1 / test.exist = 1 THEN 17 | TRUE 18 | ELSE 19 | (1 / zero)::BOOLEAN 20 | END AS res 21 | FROM test 22 | ; 23 | 24 | -- Test if the view runs without errors 25 | WITH test AS 26 | ( 27 | SELECT count(*) as key_count 28 | , 0 AS zero 29 | FROM pg_object_ownership 30 | ) 31 | SELECT 32 | CASE 33 | WHEN key_count >= 0 THEN 34 | TRUE 35 | ELSE 36 | (1 / zero)::BOOLEAN 37 | END AS res 38 | FROM test 39 | ; 40 | 41 | ROLLBACK; 42 | -------------------------------------------------------------------------------- /test/sql/view_pg_partitioned_tables_infos.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for view pg_partitioned_tables_infos 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | 7 | DO $$ 8 | DECLARE 9 | version_greater_11 BOOLEAN; 10 | res BOOLEAN; 11 | BEGIN 12 | SELECT to_number((string_to_array(version(), ' '))[2], '999.99') >= 11 INTO version_greater_11; 13 | 14 | IF version_greater_11 THEN 15 | -- Test if the function exists 16 | WITH test AS 17 | ( 18 | SELECT COUNT(*) AS exist 19 | , 0 AS zero 20 | FROM pg_catalog.pg_views 21 | WHERE viewname = 'pg_partitioned_tables_infos' 22 | ) 23 | SELECT 24 | CASE 25 | WHEN 1 / test.exist = 1 THEN 26 | TRUE 27 | ELSE 28 | (1 / zero)::BOOLEAN 29 | END AS res 30 | FROM test 31 | INTO res 32 | ; 33 | 34 | -- Test if the view runs without errors 35 | WITH test AS 36 | ( 37 | SELECT count(*) as key_count 38 | , 0 AS zero 39 | FROM pg_partitioned_tables_infos 40 | ) 41 | SELECT 42 | CASE 43 | WHEN key_count >= 0 THEN 44 | TRUE 45 | ELSE 46 | (1 / zero)::BOOLEAN 47 | END AS res 48 | FROM test 49 | INTO res 50 | ; 51 | 52 | ROLLBACK; 53 | END IF; 54 | 55 | END $$; 56 | -------------------------------------------------------------------------------- /test/sql/view_pg_table_matview_infos.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for view pg_table_matview_infos 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_views 14 | WHERE viewname = 'pg_table_matview_infos' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test if the view runs without errors 27 | WITH test AS 28 | ( 29 | SELECT count(*) as key_count 30 | , 0 AS zero 31 | FROM pg_table_matview_infos 32 | ) 33 | SELECT 34 | CASE 35 | WHEN key_count >= 0 THEN 36 | TRUE 37 | ELSE 38 | (1 / zero)::BOOLEAN 39 | END AS res 40 | FROM test 41 | ; 42 | 43 | ROLLBACK; 44 | -------------------------------------------------------------------------------- /test/sql/view_pg_unused_indexes.sql: -------------------------------------------------------------------------------- 1 | /** 2 | * Test for view pg_unused_indexes 3 | * 4 | * Every test does raise division by zero if it failes 5 | */ 6 | BEGIN; 7 | 8 | -- Test if the function exists 9 | WITH test AS 10 | ( 11 | SELECT COUNT(*) AS exist 12 | , 0 AS zero 13 | FROM pg_catalog.pg_views 14 | WHERE viewname = 'pg_unused_indexes' 15 | ) 16 | SELECT 17 | CASE 18 | WHEN 1 / test.exist = 1 THEN 19 | TRUE 20 | ELSE 21 | (1 / zero)::BOOLEAN 22 | END AS res 23 | FROM test 24 | ; 25 | 26 | -- Test if the view runs without errors 27 | WITH test AS 28 | ( 29 | SELECT count(*) as key_count 30 | , 0 AS zero 31 | FROM pg_db_views 32 | ) 33 | SELECT 34 | CASE 35 | WHEN key_count >= 0 THEN 36 | TRUE 37 | ELSE 38 | (1 / zero)::BOOLEAN 39 | END AS res 40 | FROM test 41 | ; 42 | 43 | ROLLBACK; 44 | --------------------------------------------------------------------------------