Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc9b5097

Browse files
committed
check that table is partitioned, create_range_update_trigger() now takes regclass
1 parent2326e59 commitc9b5097

File tree

2 files changed

+82
-27
lines changed

2 files changed

+82
-27
lines changed

‎hash.sql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,10 @@ DECLARE
243243
atttypeTEXT;
244244
hashfuncTEXT;
245245
BEGIN
246-
relation := @extschema@.validate_relname(relation);
247-
248246
SELECT* INTO plain_schema, plain_relname
249247
FROM @extschema@.get_plain_schema_and_relname(relation);
250248

251-
relid := relation::regclass::oid;
249+
relid := relation::oid;
252250
SELECT string_agg(attname,','),
253251
string_agg('OLD.'|| attname,','),
254252
string_agg('NEW.'|| attname,','),
@@ -264,6 +262,11 @@ BEGIN
264262
att_fmt;
265263

266264
attr := attnameFROM @extschema@.pathman_configWHERE relname::regclass= relation;
265+
266+
IF attr ISNULL THEN
267+
RAISE EXCEPTION'Table % is not partitioned', quote_ident(relation::TEXT);
268+
END IF;
269+
267270
partitions_count :=COUNT(*)FROM pg_inheritsWHERE inhparent= relation::oid;
268271

269272
/* Function name, trigger name and child relname template*/

‎range.sql

Lines changed: 76 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ BEGIN
423423
v_attname := attnameFROM @extschema@.pathman_config
424424
WHERE relname::regclass= p_parent;
425425

426+
IF v_attname ISNULL THEN
427+
RAISE EXCEPTION'Table % is not partitioned', quote_ident(p_parent::TEXT);
428+
END IF;
429+
426430
SELECT* INTO v_plain_schema, v_plain_relname
427431
FROM @extschema@.get_plain_schema_and_relname(p_parent);
428432

@@ -494,9 +498,15 @@ BEGIN
494498
FROM pg_inherits
495499
WHERE inhrelid= v_child_relid;
496500

497-
SELECT attname, parttype INTO v_attname, v_part_type
501+
SELECT attname, parttype
498502
FROM @extschema@.pathman_config
499-
WHERE relname::regclass= v_parent_relid::regclass;
503+
WHERE relname::regclass= v_parent_relid::regclass
504+
INTO v_attname, v_part_type;
505+
506+
IF v_attname ISNULL THEN
507+
RAISE EXCEPTION'Table % is not partitioned',
508+
quote_ident(v_parent_relid::regclass::text);
509+
END IF;
500510

501511
SELECT* INTO v_plain_schema, v_plain_relname
502512
FROM @extschema@.get_plain_schema_and_relname(p_partition);
@@ -591,9 +601,15 @@ BEGIN
591601
RAISE EXCEPTION'Cannot merge partitions having different parents';
592602
END IF;
593603

594-
SELECT attname, parttype INTO v_attname, v_part_type
604+
SELECT attname, parttype
595605
FROM @extschema@.pathman_config
596-
WHERE relname::regclass= v_parent_relid1::regclass;
606+
WHERE relname::regclass= v_parent_relid1::regclass
607+
INTO v_attname, v_part_type;
608+
609+
IF v_attname ISNULL THEN
610+
RAISE EXCEPTION'Table % is not partitioned',
611+
quote_ident(v_parent_relid1::regclass::text);
612+
END IF;
597613

598614
/* Check if this is RANGE partition*/
599615
IF v_part_type!=2 THEN
@@ -637,8 +653,14 @@ DECLARE
637653
v_child_relnameTEXT;
638654
v_check_nameTEXT;
639655
BEGIN
640-
SELECT attname INTO v_attnameFROM @extschema@.pathman_config
641-
WHERE relname::regclass= p_parent_relid::regclass;
656+
SELECT attnameFROM @extschema@.pathman_config
657+
WHERE relname::regclass= p_parent_relid::regclass
658+
INTO v_attname;
659+
660+
IF v_attname ISNULL THEN
661+
RAISE EXCEPTION'Table % is not partitioned',
662+
quote_ident(p_parent_relid::regclass::text);
663+
END IF;
642664

643665
SELECT* INTO v_plain_schema, v_plain_relname
644666
FROM @extschema@.get_plain_schema_and_relname(p_part1);
@@ -694,16 +716,22 @@ CREATE OR REPLACE FUNCTION @extschema@.append_range_partition(
694716
RETURNSTEXTAS
695717
$$
696718
DECLARE
697-
v_attnameTEXT;
698-
v_atttypeTEXT;
699-
v_part_nameTEXT;
700-
v_intervalTEXT;
719+
v_attnameTEXT;
720+
v_atttypeTEXT;
721+
v_part_nameTEXT;
722+
v_intervalTEXT;
701723
BEGIN
702724
/* Prevent concurrent partition creation*/
703725
PERFORM @extschema@.acquire_partitions_lock();
704726

705-
SELECT attname, range_interval INTO v_attname, v_interval
706-
FROM @extschema@.pathman_configWHERE relname::regclass= p_relation;
727+
SELECT attname, range_interval
728+
FROM @extschema@.pathman_config
729+
WHERE relname::regclass= p_relation
730+
INTO v_attname, v_interval;
731+
732+
IF v_attname ISNULL THEN
733+
RAISE EXCEPTION'Table % is not partitioned', quote_ident(p_relation::TEXT);
734+
END IF;
707735

708736
v_atttype := @extschema@.get_attribute_type_name(p_relation, v_attname);
709737

@@ -770,8 +798,15 @@ BEGIN
770798
/* Prevent concurrent partition creation*/
771799
PERFORM @extschema@.acquire_partitions_lock();
772800

773-
SELECT attname, range_interval INTO v_attname, v_interval
774-
FROM @extschema@.pathman_configWHERE relname::regclass= p_relation;
801+
SELECT attname, range_interval
802+
FROM @extschema@.pathman_config
803+
WHERE relname::regclass= p_relation
804+
INTO v_attname, v_interval;
805+
806+
IF v_attname ISNULL THEN
807+
RAISE EXCEPTION'Table % is not partitioned', quote_ident(p_relation::TEXT);
808+
END IF;
809+
775810
v_atttype := @extschema@.get_attribute_type_name(p_relation, v_attname);
776811

777812
EXECUTE format('SELECT @extschema@.prepend_partition_internal($1, $2, $3, ARRAY[]::%s[])', v_atttype)
@@ -946,7 +981,14 @@ BEGIN
946981
, p_relation);
947982

948983
/* Set check constraint*/
949-
v_attname := attnameFROM @extschema@.pathman_configWHERE relname::regclass= p_relation;
984+
v_attname := attname
985+
FROM @extschema@.pathman_config
986+
WHERE relname::regclass= p_relation;
987+
988+
IF v_attname ISNULL THEN
989+
RAISE EXCEPTION'Table % is not partitioned', quote_ident(p_relation::TEXT);
990+
END IF;
991+
950992
v_cond := @extschema@.get_range_condition(v_attname, p_start_value, p_end_value);
951993

952994
/* Plain partition name and schema*/
@@ -1072,7 +1114,7 @@ $$ LANGUAGE plpgsql;
10721114
* Creates an update trigger
10731115
*/
10741116
CREATEOR REPLACE FUNCTION @extschema@.create_range_update_trigger(
1075-
IN relationTEXT)
1117+
IN relationREGCLASS)
10761118
RETURNSTEXTAS
10771119
$$
10781120
DECLARE
@@ -1107,8 +1149,7 @@ DECLARE
11071149
numINTEGER :=0;
11081150
attrTEXT;
11091151
BEGIN
1110-
relation := @extschema@.validate_relname(relation);
1111-
relid := relation::regclass::oid;
1152+
relid := relation::oid;
11121153
SELECT string_agg(attname,','),
11131154
string_agg('OLD.'|| attname,','),
11141155
string_agg('NEW.'|| attname,','),
@@ -1123,7 +1164,14 @@ BEGIN
11231164
att_val_fmt,
11241165
att_fmt;
11251166

1126-
attr := attnameFROM @extschema@.pathman_configWHERE relname= relation;
1167+
attr := attname
1168+
FROM @extschema@.pathman_config
1169+
WHERE relname::regclass= relation;
1170+
1171+
IF attr ISNULL THEN
1172+
RAISE EXCEPTION'Table % is not partitioned', quote_ident(relation::TEXT);
1173+
END IF;
1174+
11271175
EXECUTE format(func, relation, attr,0, att_val_fmt,
11281176
old_fields, att_fmt, new_fields);
11291177
FOR recin (SELECT*FROM pg_inheritsWHERE inhparent= relation::regclass::oid)
@@ -1215,7 +1263,6 @@ CREATE OR REPLACE FUNCTION @extschema@.append_partitions_on_demand_internal(
12151263
RETURNSOIDAS
12161264
$$
12171265
DECLARE
1218-
v_relationTEXT;
12191266
v_cntINTEGER :=0;
12201267
iINTEGER :=0;
12211268
v_partTEXT;
@@ -1227,11 +1274,16 @@ DECLARE
12271274
v_next_value p_new_value%TYPE;
12281275
v_is_dateBOOLEAN;
12291276
BEGIN
1230-
v_relation := @extschema@.validate_relname(p_relid::regclass::text);
1231-
12321277
/* get attribute name and interval*/
1233-
SELECT attname, range_interval INTO v_attname, v_interval
1234-
FROM @extschema@.pathman_configWHERE relname= v_relation;
1278+
SELECT attname, range_interval
1279+
FROM @extschema@.pathman_config
1280+
WHERE relname::regclass= p_relid::regclass
1281+
INTO v_attname, v_interval;
1282+
1283+
IF v_attname ISNULL THEN
1284+
RAISE EXCEPTION'Table % is not partitioned',
1285+
quote_ident(p_relid::regclass::text);
1286+
END IF;
12351287

12361288
v_min := @extschema@.get_min_range_value(p_relid::regclass::oid, p_new_value);
12371289
v_max := @extschema@.get_max_range_value(p_relid::regclass::oid, p_new_value);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp