
-- psql postgres
CREATE DATABASE test
  WITH OWNER = et
       ENCODING = 'UTF8'
       LC_COLLATE = 'de_DE.UTF-8'
       LC_CTYPE = 'de_DE.UTF-8'
       CONNECTION LIMIT = -1
;

\c test

DROP TYPE t_kpos CASCADE;
CREATE TYPE t_kpos AS (
    Pos         smallint
  , Count       smallint
  , Konto       integer
  , Sign        smallint
  , BTyp        smallint
  , Betrag      bigint
);

DROP FUNCTION IF EXISTS setof_kpos;
CREATE OR REPLACE FUNCTION setof_kpos(kontopositionen text) RETURNS SETOF t_kpos
  AS '/var/lib/postgresql/lib/13/test', 'set_of_kpos'
  LANGUAGE C IMMUTABLE STRICT
  PARALLEL SAFE
;
COMMIT;
SELECT * FROM setof_kpos('11.40,11052,-1,328;9.58,4736,1,226;1.82,3806,1,314');

DROP TABLE kpos_test;
CREATE TABLE kpos_test (id int, kpos text);
INSERT INTO kpos_test SELECT generate_series(1,10000000) AS id, '11.40,11052,-1,328;9.58,4736,1,226;1.82,3806,1,314' AS kpos;
COMMIT;

-- psql -h postgres.vmware -p 5433 test
SET max_parallel_workers_per_gather TO 4;
-- SELECT setof_kpos('');
SELECT sum(sign*Betrag) FROM kpos_test, setof_kpos(kpos);
\q

