Skip to content

Commit c758c4b

Browse files
committed
pathman: plpgsql functions return values
1 parent af522cd commit c758c4b

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

contrib/pg_pathman/expected/pg_pathman.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ NOTICE: Copying data to test.range_rel_2 (condition: ((dt >= 'Sun Feb 01 00:00:
3434
NOTICE: Copying data to test.range_rel_1 (condition: ((dt >= 'Thu Jan 01 00:00:00 2015'::timestamp without time zone) AND (dt < 'Sun Feb 01 00:00:00 2015'::timestamp without time zone)))
3535
partition_data
3636
----------------
37-
0
37+
120
3838
(1 row)
3939

4040
CREATE TABLE test.num_range_rel (
@@ -81,9 +81,9 @@ SELECT * FROM test.hash_rel WHERE value = 7;
8181
(1 row)
8282

8383
SELECT pathman.create_range_update_trigger('test.num_range_rel');
84-
create_range_update_trigger
85-
-----------------------------
86-
84+
create_range_update_trigger
85+
------------------------------------------
86+
test.num_range_rel_update_trigger_func()
8787
(1 row)
8888

8989
UPDATE test.num_range_rel SET id = 3001 WHERE id = 1;
@@ -518,7 +518,7 @@ NOTICE: Copying data to hash_rel_1 (condition: ((value % 3) = 1))
518518
NOTICE: Copying data to hash_rel_2 (condition: ((value % 3) = 2))
519519
partition_data
520520
----------------
521-
0
521+
10000
522522
(1 row)
523523

524524
EXPLAIN (COSTS OFF) SELECT * FROM hash_rel WHERE id = 1234;
@@ -562,7 +562,7 @@ NOTICE: Copying data to range_rel_11 (condition: ((dt >= 'Mon Nov 01 00:00:00 2
562562
NOTICE: Copying data to range_rel_12 (condition: ((dt >= 'Wed Dec 01 00:00:00 2010'::timestamp without time zone) AND (dt < 'Sat Jan 01 00:00:00 2011'::timestamp without time zone)))
563563
partition_data
564564
----------------
565-
0
565+
365
566566
(1 row)
567567

568568
SELECT merge_range_partitions('range_rel_1', 'range_rel_2');

contrib/pg_pathman/sql/init.sql

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ RETURNS ANYARRAY AS 'pg_pathman', 'get_range_by_idx' LANGUAGE C STRICT;
4141
/*
4242
* Copy rows to partitions
4343
*/
44-
CREATE OR REPLACE FUNCTION @extschema@.partition_data(p_parent text)
45-
RETURNS bigint AS
44+
CREATE OR REPLACE FUNCTION @extschema@.partition_data(p_parent text, OUT p_total BIGINT)
45+
AS
4646
$$
4747
DECLARE
4848
rec RECORD;
49+
cnt BIGINT := 0;
4950
BEGIN
5051
p_parent := @extschema@.validate_relname(p_parent);
52+
53+
p_total := 0;
5154
FOR rec IN (SELECT inhrelid as child_id, pg_constraint.consrc
5255
FROM @extschema@.pathman_config as cfg
5356
JOIN pg_class AS parent ON parent.relfilenode = cfg.relname::regclass::oid
@@ -62,8 +65,9 @@ BEGIN
6265
, p_parent
6366
, rec.consrc
6467
, rec.child_id::regclass::text);
68+
GET DIAGNOSTICS cnt = ROW_COUNT;
69+
p_total := p_total + cnt;
6570
END LOOP;
66-
RETURN 0;
6771
END
6872
$$
6973
LANGUAGE plpgsql;

contrib/pg_pathman/sql/range.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ BEGIN
262262
END
263263
$$ LANGUAGE plpgsql;
264264

265-
266265
/*
267266
* Split RANGE partition
268267
*/
@@ -596,7 +595,7 @@ $$ LANGUAGE plpgsql;
596595
*/
597596
CREATE OR REPLACE FUNCTION @extschema@.create_range_update_trigger(
598597
IN relation TEXT)
599-
RETURNS VOID AS
598+
RETURNS TEXT AS
600599
$$
601600
DECLARE
602601
func TEXT := '
@@ -630,6 +629,7 @@ DECLARE
630629
num INTEGER := 0;
631630
attr TEXT;
632631
BEGIN
632+
relation := @extschema@.validate_relname(relation);
633633
relid := relation::regclass::oid;
634634
SELECT string_agg(attname, ', '),
635635
string_agg('OLD.' || attname, ', '),
@@ -656,6 +656,8 @@ BEGIN
656656
, relation);
657657
num := num + 1;
658658
END LOOP;
659+
660+
RETURN format('%s_update_trigger_func()', relation);
659661
END
660662
$$ LANGUAGE plpgsql;
661663

0 commit comments

Comments
 (0)