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

Commitec40a7c

Browse files
committed
fix interval validation for negative values
1 parent52375ca commitec40a7c

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

‎expected/pathman_interval.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ ERROR: cannot find appropriate partition for key '250'
2020
/* Set a trivial interval */
2121
SELECT set_interval('abc', 0);
2222
ERROR: interval must not be trivial
23+
/* Set a negative interval */
24+
SELECT set_interval('abc', -100);
25+
ERROR: interval must not be negative
2326
/* We also shouldn't be able to set a trivial interval directly in pathman_config table */
2427
UPDATE pathman_config SET range_interval = '0' WHERE partrel = 'abc'::REGCLASS;
2528
ERROR: interval must not be trivial

‎sql/pathman_interval.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ SELECT set_interval('abc', NULL::INTEGER);
99
INSERT INTO abcVALUES (250);
1010
/* Set a trivial interval*/
1111
SELECT set_interval('abc',0);
12+
/* Set a negative interval*/
13+
SELECT set_interval('abc',-100);
1214
/* We also shouldn't be able to set a trivial interval directly in pathman_config table*/
1315
UPDATE pathman_configSET range_interval='0'WHERE partrel='abc'::REGCLASS;
1416
/* Set a normal interval*/

‎src/pl_range_funcs.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ interval_is_trivial(Oid atttype, Datum interval, Oid interval_type)
684684
Operatorop;
685685
Oidop_func;
686686
FmgrInfocmp_func;
687+
int32cmp_result;
687688

688689
/* Generate default value */
689690
switch(atttype)
@@ -754,8 +755,13 @@ interval_is_trivial(Oid atttype, Datum interval, Oid interval_type)
754755
fill_type_cmp_fmgr_info(&cmp_func,
755756
getBaseType(atttype),
756757
getBaseType(op_result_type));
757-
if (DatumGetInt32(FunctionCall2(&cmp_func,default_value,op_result))==0)
758+
cmp_result=DatumGetInt32(FunctionCall2(&cmp_func,
759+
default_value,
760+
op_result));
761+
if (cmp_result==0)
758762
return true;
763+
elseif (cmp_result>0)/* Negative interval? */
764+
elog(ERROR,"interval must not be negative");
759765

760766
return false;
761767
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp