提交 e98f75fc authored 作者: sylvain-ilm's avatar sylvain-ilm

test PG mode, null parameters and lowerBound > upperBound

上级 ab631dcb
......@@ -1580,6 +1580,12 @@ public class Function extends Expression implements FunctionCall {
// https://www.postgresql.org/docs/current/arrays.html#ARRAYS-ACCESSING
// For historical reasons postgreSQL ignore invalid indexes
final boolean isPG = database.getMode().getEnum() == ModeEnum.PostgreSQL;
if (index1 > index2) {
if (isPG)
result = ValueArray.get(array.getComponentType(), new Value[0]);
else
result = ValueNull.INSTANCE;
} else {
if (index1 < 0) {
if (isPG)
index1 = 0;
......@@ -1592,6 +1598,7 @@ public class Function extends Expression implements FunctionCall {
else
result = ValueNull.INSTANCE;
}
}
if (result == null)
result = ValueArray.get(array.getComponentType(), Arrays.copyOfRange(array.getList(), index1, index2));
break;
......
......@@ -9,8 +9,38 @@ select array_slice(ARRAY[1, 2, 3, 4], 1, 1) = ARRAY[1];
select array_slice(ARRAY[1, 2, 3, 4], 1, 3) = ARRAY[1, 2, 3];
>> TRUE
-- test invalid indexes
select array_slice(ARRAY[1, 2, 3, 4], 3, 1) is null;
>> TRUE
select array_slice(ARRAY[1, 2, 3, 4], 0, 3) is null;
>> TRUE
select array_slice(ARRAY[1, 2, 3, 4], 1, 5) is null;
>> TRUE
-- in PostgreSQL, indexes are corrected
SET MODE PostgreSQL;
> ok
select array_slice(ARRAY[1, 2, 3, 4], 3, 1) = ARRAY[];
>> TRUE
select array_slice(ARRAY[1, 2, 3, 4], 0, 3) = ARRAY[1, 2, 3];
>> TRUE
select array_slice(ARRAY[1, 2, 3, 4], 1, 5) = ARRAY[1, 2, 3, 4];
>> TRUE
SET MODE Regular;
> ok
-- null parameters
select array_slice(null, 1, 3) is null;
>> TRUE
select array_slice(ARRAY[1, 2, 3, 4], null, 3) is null;
>> TRUE
select array_slice(ARRAY[1, 2, 3, 4], 1, null) is null;
>> TRUE
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论