diff --git a/src/common/backend/utils/adt/arrayfuncs.cpp b/src/common/backend/utils/adt/arrayfuncs.cpp index 507607469..6e6ceb3cd 100644 --- a/src/common/backend/utils/adt/arrayfuncs.cpp +++ b/src/common/backend/utils/adt/arrayfuncs.cpp @@ -1787,7 +1787,8 @@ Datum array_varchar_exists(PG_FUNCTION_ARGS) PG_RETURN_BOOL(false); } Datum index_datum = PG_GETARG_DATUM(1); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_varchar_exists must be call in procedure"))); } @@ -1821,7 +1822,8 @@ Datum array_integer_exists(PG_FUNCTION_ARGS) PG_RETURN_BOOL(false); } Datum index_datum = PG_GETARG_DATUM(1); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_integer_exists must be call in procedure"))); } @@ -1966,7 +1968,8 @@ Datum array_varchar_next(PG_FUNCTION_ARGS) int index = 0; Datum index_datum = PG_GETARG_DATUM(1); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_varchar_next must be call in procedure"))); } @@ -2016,7 +2019,8 @@ Datum array_varchar_prior(PG_FUNCTION_ARGS) int index = 0; Datum index_datum = PG_GETARG_DATUM(1); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_varchar_prior must be call in procedure"))); } @@ -2061,7 +2065,8 @@ Datum array_varchar_first(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_varchar_first must be call in procedure"))); } @@ -2108,7 +2113,8 @@ Datum array_integer_next(PG_FUNCTION_ARGS) } Datum index_datum = PG_GETARG_DATUM(1); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_integer_next must be call in procedure"))); } @@ -2165,7 +2171,8 @@ Datum array_integer_prior(PG_FUNCTION_ARGS) } Datum index_datum = PG_GETARG_DATUM(1); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_integer_prior must be call in procedure"))); } @@ -2218,7 +2225,8 @@ Datum array_integer_first(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_integer_first must be call in procedure"))); } @@ -2262,7 +2270,8 @@ Datum array_integer_last(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_integer_last must be call in procedure"))); } @@ -2287,7 +2296,8 @@ Datum array_varchar_last(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_varchar_last must be call in procedure"))); } @@ -2343,7 +2353,8 @@ Datum array_integer_deleteidx(PG_FUNCTION_ARGS) } Datum index_datum = PG_GETARG_DATUM(1); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_integer_deleteidx must be call in procedure"))); } @@ -2368,7 +2379,8 @@ Datum array_varchar_deleteidx(PG_FUNCTION_ARGS) } Datum index_datum = PG_GETARG_DATUM(1); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_varchar_deleteidx must be call in procedure"))); } @@ -2575,7 +2587,8 @@ Datum array_indexby_delete(PG_FUNCTION_ARGS) checkEnv(); ArrayType* v = PG_GETARG_ARRAYTYPE_P(0); ArrayType* array = construct_empty_array(ARR_ELEMTYPE(v)); - if (u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { + if (u_sess->SPI_cxt.cur_tableof_index == NULL || + u_sess->SPI_cxt.cur_tableof_index->tableOfIndex == NULL) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("array_indexby_delete must be call in procedure"))); } diff --git a/src/test/regress/expected/arrayinterface_indexby.out b/src/test/regress/expected/arrayinterface_indexby.out index bb4f290f8..9983004f2 100644 --- a/src/test/regress/expected/arrayinterface_indexby.out +++ b/src/test/regress/expected/arrayinterface_indexby.out @@ -11,6 +11,10 @@ drop schema if exists plpgsql_array_interface_indexby; NOTICE: schema "plpgsql_array_interface_indexby" does not exist, skipping create schema plpgsql_array_interface_indexby; set current_schema = plpgsql_array_interface_indexby; +-- must be call in procedure -- +select array_indexby_delete(array[1, 2]); +ERROR: array_indexby_delete must be call in procedure +CONTEXT: referenced column: array_indexby_delete -- test array interface count -- create or replace procedure array_interface_p1() as declare diff --git a/src/test/regress/expected/arrayinterface_single.out b/src/test/regress/expected/arrayinterface_single.out index f06112f97..f7954f60b 100644 --- a/src/test/regress/expected/arrayinterface_single.out +++ b/src/test/regress/expected/arrayinterface_single.out @@ -11,6 +11,43 @@ drop schema if exists plpgsql_array_interface; NOTICE: schema "plpgsql_array_interface" does not exist, skipping create schema plpgsql_array_interface; set current_schema = plpgsql_array_interface; +-- must be call in procedure -- +select array_varchar_exists(array['1', '2'], '3'); +ERROR: array_varchar_exists must be call in procedure +CONTEXT: referenced column: array_varchar_exists +select array_varchar_next(array['1','2'], '3'); +ERROR: array_varchar_next must be call in procedure +CONTEXT: referenced column: array_varchar_next +select array_varchar_prior(array['1','2'], '3'); +ERROR: array_varchar_prior must be call in procedure +CONTEXT: referenced column: array_varchar_prior +select array_varchar_first(array['1','2']); +ERROR: array_varchar_first must be call in procedure +CONTEXT: referenced column: array_varchar_first +select array_varchar_last(array['1','2']); +ERROR: array_varchar_last must be call in procedure +CONTEXT: referenced column: array_varchar_last +select array_varchar_deleteidx(array['1','2'], '3'); +ERROR: array_varchar_deleteidx must be call in procedure +CONTEXT: referenced column: array_varchar_deleteidx +select array_integer_exists(array[1, 2], 3); +ERROR: array_integer_exists must be call in procedure +CONTEXT: referenced column: array_integer_exists +select array_integer_next(array[1, 2], 3); +ERROR: array_integer_next must be call in procedure +CONTEXT: referenced column: array_integer_next +select array_integer_prior(array[1, 2], 3); +ERROR: array_integer_prior must be call in procedure +CONTEXT: referenced column: array_integer_prior +select array_integer_first(array[1, 2]); +ERROR: array_integer_first must be call in procedure +CONTEXT: referenced column: array_integer_first +select array_integer_last(array[1, 2]); +ERROR: array_integer_last must be call in procedure +CONTEXT: referenced column: array_integer_last +select array_integer_deleteidx(array[1, 2], 3); +ERROR: array_integer_deleteidx must be call in procedure +CONTEXT: referenced column: array_integer_deleteidx -- test array interface count -- create or replace procedure array_interface_p1() as diff --git a/src/test/regress/sql/arrayinterface_indexby.sql b/src/test/regress/sql/arrayinterface_indexby.sql index f347aeae0..b0c96121f 100644 --- a/src/test/regress/sql/arrayinterface_indexby.sql +++ b/src/test/regress/sql/arrayinterface_indexby.sql @@ -8,6 +8,10 @@ drop schema if exists plpgsql_array_interface_indexby; create schema plpgsql_array_interface_indexby; set current_schema = plpgsql_array_interface_indexby; +-- must be call in procedure -- +select array_indexby_delete(array[1, 2]); + + -- test array interface count -- create or replace procedure array_interface_p1() as declare diff --git a/src/test/regress/sql/arrayinterface_single.sql b/src/test/regress/sql/arrayinterface_single.sql index efa5a0468..6ddb967f4 100644 --- a/src/test/regress/sql/arrayinterface_single.sql +++ b/src/test/regress/sql/arrayinterface_single.sql @@ -8,6 +8,22 @@ drop schema if exists plpgsql_array_interface; create schema plpgsql_array_interface; set current_schema = plpgsql_array_interface; +-- must be call in procedure -- +select array_varchar_exists(array['1', '2'], '3'); +select array_varchar_next(array['1','2'], '3'); +select array_varchar_prior(array['1','2'], '3'); +select array_varchar_first(array['1','2']); +select array_varchar_last(array['1','2']); +select array_varchar_deleteidx(array['1','2'], '3'); + +select array_integer_exists(array[1, 2], 3); +select array_integer_next(array[1, 2], 3); +select array_integer_prior(array[1, 2], 3); +select array_integer_first(array[1, 2]); +select array_integer_last(array[1, 2]); +select array_integer_deleteidx(array[1, 2], 3); + + -- test array interface count -- create or replace procedure array_interface_p1() as