Skip to content

Commit cd3b01e

Browse files
committed
create_single_range_partition() function fix
1 parent fa1429e commit cd3b01e

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

expected/pathman_basic.out

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,34 +1912,34 @@ NOTICE: sequence "index_on_childs_seq" does not exist, skipping
19121912
0
19131913
(1 row)
19141914

1915-
SELECT add_range_partition('test.index_on_childs', 1, 1000, 'test.index_on_childs_1_1K');
1915+
SELECT add_range_partition('test.index_on_childs', 1, 1000, 'test.index_on_childs_1_1k');
19161916
add_range_partition
19171917
---------------------------
1918-
test.index_on_childs_1_1K
1918+
test.index_on_childs_1_1k
19191919
(1 row)
19201920

1921-
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_1K_2K');
1921+
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_1k_2k');
19221922
append_range_partition
19231923
----------------------------
1924-
test.index_on_childs_1K_2K
1924+
test.index_on_childs_1k_2k
19251925
(1 row)
19261926

1927-
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_2K_3K');
1927+
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_2k_3k');
19281928
append_range_partition
19291929
----------------------------
1930-
test.index_on_childs_2K_3K
1930+
test.index_on_childs_2k_3k
19311931
(1 row)
19321932

1933-
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_3K_4K');
1933+
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_3k_4k');
19341934
append_range_partition
19351935
----------------------------
1936-
test.index_on_childs_3K_4K
1936+
test.index_on_childs_3k_4k
19371937
(1 row)
19381938

1939-
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_4K_5K');
1939+
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_4k_5k');
19401940
append_range_partition
19411941
----------------------------
1942-
test.index_on_childs_4K_5K
1942+
test.index_on_childs_4k_5k
19431943
(1 row)
19441944

19451945
SELECT set_enable_parent('test.index_on_childs', true);

range.sql

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ CREATE OR REPLACE FUNCTION @extschema@.create_single_range_partition(
460460
end_value ANYELEMENT,
461461
partition_name TEXT DEFAULT NULL,
462462
tablespace TEXT DEFAULT NULL)
463-
RETURNS TEXT AS
463+
RETURNS REGCLASS AS
464464
$$
465465
DECLARE
466466
v_part_num INT;
@@ -472,7 +472,7 @@ DECLARE
472472
v_child_relname_exists BOOL;
473473
v_seq_name TEXT;
474474
v_init_callback REGPROCEDURE;
475-
475+
v_result REGCLASS;
476476
BEGIN
477477
v_attname := attname FROM @extschema@.pathman_config
478478
WHERE partrel = parent_relid;
@@ -535,13 +535,20 @@ BEGIN
535535
ON params.partrel = parent_relid
536536
INTO v_init_callback;
537537

538+
/*
539+
* Save the regclass value because in callback user may want to rename
540+
* partition
541+
*/
542+
v_result := v_child_relname::regclass;
543+
544+
/* Invoke callback */
538545
PERFORM @extschema@.invoke_on_partition_created_callback(parent_relid,
539546
v_child_relname::REGCLASS,
540547
v_init_callback,
541548
start_value,
542549
end_value);
543550

544-
RETURN v_child_relname;
551+
RETURN v_result;
545552
END
546553
$$ LANGUAGE plpgsql
547554
SET client_min_messages = WARNING;

sql/pathman_basic.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,11 @@ CREATE TABLE test.index_on_childs(c1 integer not null, c2 integer);
498498
CREATE INDEX ON test.index_on_childs(c2);
499499
INSERT INTO test.index_on_childs SELECT i, (random()*10000)::integer FROM generate_series(1, 10000) i;
500500
SELECT create_range_partitions('test.index_on_childs', 'c1', 1, 1000, 0, false);
501-
SELECT add_range_partition('test.index_on_childs', 1, 1000, 'test.index_on_childs_1_1K');
502-
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_1K_2K');
503-
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_2K_3K');
504-
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_3K_4K');
505-
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_4K_5K');
501+
SELECT add_range_partition('test.index_on_childs', 1, 1000, 'test.index_on_childs_1_1k');
502+
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_1k_2k');
503+
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_2k_3k');
504+
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_3k_4k');
505+
SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_4k_5k');
506506
SELECT set_enable_parent('test.index_on_childs', true);
507507
VACUUM ANALYZE test.index_on_childs;
508508
EXPLAIN (COSTS OFF) SELECT * FROM test.index_on_childs WHERE c1 > 100 AND c1 < 2500 AND c2 = 500;

src/pg_pathman.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,7 @@ spawn_partitions(Oid partitioned_rel, /* parent's Oid */
582582
char *query;
583583

584584
/* Create querty statement */
585-
query = psprintf("SELECT part::regclass "
586-
"FROM %s.create_single_range_partition($1, $2, $3) AS part",
585+
query = psprintf("SELECT %s.create_single_range_partition($1, $2, $3) AS part",
587586
get_namespace_name(get_pathman_schema()));
588587

589588
/* Execute comparison function cmp(value, cur_part_leading) */

0 commit comments

Comments
 (0)