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

test PG mode, null parameters and lowerBound > upperBound

上级 ab631dcb
...@@ -1580,17 +1580,24 @@ public class Function extends Expression implements FunctionCall { ...@@ -1580,17 +1580,24 @@ public class Function extends Expression implements FunctionCall {
// https://www.postgresql.org/docs/current/arrays.html#ARRAYS-ACCESSING // https://www.postgresql.org/docs/current/arrays.html#ARRAYS-ACCESSING
// For historical reasons postgreSQL ignore invalid indexes // For historical reasons postgreSQL ignore invalid indexes
final boolean isPG = database.getMode().getEnum() == ModeEnum.PostgreSQL; final boolean isPG = database.getMode().getEnum() == ModeEnum.PostgreSQL;
if (index1 < 0) { if (index1 > index2) {
if (isPG) if (isPG)
index1 = 0; result = ValueArray.get(array.getComponentType(), new Value[0]);
else
result = ValueNull.INSTANCE;
}
if (index2 > array.getList().length) {
if (isPG)
index2 = array.getList().length;
else else
result = ValueNull.INSTANCE; result = ValueNull.INSTANCE;
} else {
if (index1 < 0) {
if (isPG)
index1 = 0;
else
result = ValueNull.INSTANCE;
}
if (index2 > array.getList().length) {
if (isPG)
index2 = array.getList().length;
else
result = ValueNull.INSTANCE;
}
} }
if (result == null) if (result == null)
result = ValueArray.get(array.getComponentType(), Arrays.copyOfRange(array.getList(), index1, index2)); result = ValueArray.get(array.getComponentType(), Arrays.copyOfRange(array.getList(), index1, index2));
......
...@@ -9,8 +9,38 @@ select array_slice(ARRAY[1, 2, 3, 4], 1, 1) = ARRAY[1]; ...@@ -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]; select array_slice(ARRAY[1, 2, 3, 4], 1, 3) = ARRAY[1, 2, 3];
>> TRUE >> 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; select array_slice(ARRAY[1, 2, 3, 4], 0, 3) is null;
>> TRUE >> TRUE
select array_slice(ARRAY[1, 2, 3, 4], 1, 5) is null; select array_slice(ARRAY[1, 2, 3, 4], 1, 5) is null;
>> TRUE >> 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论