summaryrefslogtreecommitdiffstats
path: root/contrib/intagg
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:17:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:17:33 +0000
commit5e45211a64149b3c659b90ff2de6fa982a5a93ed (patch)
tree739caf8c461053357daa9f162bef34516c7bf452 /contrib/intagg
parentInitial commit. (diff)
downloadpostgresql-15-5e45211a64149b3c659b90ff2de6fa982a5a93ed.tar.xz
postgresql-15-5e45211a64149b3c659b90ff2de6fa982a5a93ed.zip
Adding upstream version 15.5.upstream/15.5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'contrib/intagg')
-rw-r--r--contrib/intagg/Makefile15
-rw-r--r--contrib/intagg/intagg--1.0--1.1.sql23
-rw-r--r--contrib/intagg/intagg--1.1.sql37
-rw-r--r--contrib/intagg/intagg.control4
4 files changed, 79 insertions, 0 deletions
diff --git a/contrib/intagg/Makefile b/contrib/intagg/Makefile
new file mode 100644
index 0000000..c645930
--- /dev/null
+++ b/contrib/intagg/Makefile
@@ -0,0 +1,15 @@
+# contrib/intagg/Makefile
+
+EXTENSION = intagg
+DATA = intagg--1.1.sql intagg--1.0--1.1.sql
+
+ifdef USE_PGXS
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
+else
+subdir = contrib/intagg
+top_builddir = ../..
+include $(top_builddir)/src/Makefile.global
+include $(top_srcdir)/contrib/contrib-global.mk
+endif
diff --git a/contrib/intagg/intagg--1.0--1.1.sql b/contrib/intagg/intagg--1.0--1.1.sql
new file mode 100644
index 0000000..c0cc17a
--- /dev/null
+++ b/contrib/intagg/intagg--1.0--1.1.sql
@@ -0,0 +1,23 @@
+/* contrib/intagg/intagg--1.0--1.1.sql */
+
+-- complain if script is sourced in psql, rather than via ALTER EXTENSION
+\echo Use "ALTER EXTENSION intagg UPDATE TO '1.1'" to load this file. \quit
+
+ALTER FUNCTION int_agg_state(internal, int4) PARALLEL SAFE;
+ALTER FUNCTION int_agg_final_array(internal) PARALLEL SAFE;
+ALTER FUNCTION int_array_enum(int4[]) PARALLEL SAFE;
+DO LANGUAGE plpgsql
+$$
+DECLARE
+ my_schema pg_catalog.text := pg_catalog.quote_ident(pg_catalog.current_schema());
+ old_path pg_catalog.text := pg_catalog.current_setting('search_path');
+BEGIN
+-- for safety, transiently set search_path to just pg_catalog+pg_temp
+PERFORM pg_catalog.set_config('search_path', 'pg_catalog, pg_temp', true);
+
+UPDATE pg_proc SET proparallel = 's'
+WHERE oid = (my_schema || '.int_array_aggregate(int4)')::pg_catalog.regprocedure;
+
+PERFORM pg_catalog.set_config('search_path', old_path, true);
+END
+$$;
diff --git a/contrib/intagg/intagg--1.1.sql b/contrib/intagg/intagg--1.1.sql
new file mode 100644
index 0000000..3796a2a
--- /dev/null
+++ b/contrib/intagg/intagg--1.1.sql
@@ -0,0 +1,37 @@
+/* contrib/intagg/intagg--1.1.sql */
+
+-- complain if script is sourced in psql, rather than via CREATE EXTENSION
+\echo Use "CREATE EXTENSION intagg" to load this file. \quit
+
+-- Internal function for the aggregate
+-- Is called for each item in an aggregation
+CREATE FUNCTION int_agg_state (internal, int4)
+RETURNS internal
+AS 'array_agg_transfn'
+PARALLEL SAFE
+LANGUAGE INTERNAL;
+
+-- Internal function for the aggregate
+-- Is called at the end of the aggregation, and returns an array.
+CREATE FUNCTION int_agg_final_array (internal)
+RETURNS int4[]
+AS 'array_agg_finalfn'
+PARALLEL SAFE
+LANGUAGE INTERNAL;
+
+-- The aggregate function itself
+-- uses the above functions to create an array of integers from an aggregation.
+CREATE AGGREGATE int_array_aggregate(int4) (
+ SFUNC = int_agg_state,
+ STYPE = internal,
+ FINALFUNC = int_agg_final_array,
+ PARALLEL = SAFE
+);
+
+-- The enumeration function
+-- returns each element in a one dimensional integer array
+-- as a row.
+CREATE FUNCTION int_array_enum(int4[])
+RETURNS setof integer
+AS 'array_unnest'
+LANGUAGE INTERNAL IMMUTABLE STRICT PARALLEL SAFE;
diff --git a/contrib/intagg/intagg.control b/contrib/intagg/intagg.control
new file mode 100644
index 0000000..a733bbf
--- /dev/null
+++ b/contrib/intagg/intagg.control
@@ -0,0 +1,4 @@
+# intagg extension
+comment = 'integer aggregator and enumerator (obsolete)'
+default_version = '1.1'
+relocatable = true