From e89be4c69d134645903a77ba83d41ed1b9c77658 Mon Sep 17 00:00:00 2001 From: Aleksander Alekseev Date: Tue, 29 Oct 2024 14:32:59 +0300 Subject: [PATCH v1] Rename trim_array() to array_trim() The new name is more consistent with the rest of array_* functions. trim_array() is kept for backward compatibility but is left undocumented. It can be removed completely in the far future. Aleksander Alekseev, reviewed by TODO FIXME Discussion: TODO FIXME BUMP CATVERSION --- doc/src/sgml/func.sgml | 6 +++--- src/backend/utils/adt/arrayfuncs.c | 2 +- src/include/catalog/pg_proc.dat | 7 +++++-- src/test/regress/expected/arrays.out | 12 ++++++------ src/test/regress/sql/arrays.sql | 10 +++++----- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 05f630c6a6..9a6dd4d776 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -20482,9 +20482,9 @@ SELECT NULLIF(value, '(none)') ... - trim_array + array_trim - trim_array ( array anyarray, n integer ) + array_trim ( array anyarray, n integer ) anyarray @@ -20492,7 +20492,7 @@ SELECT NULLIF(value, '(none)') ... If the array is multidimensional, only the first dimension is trimmed. - trim_array(ARRAY[1,2,3,4,5,6], 2) + array_trim(ARRAY[1,2,3,4,5,6], 2) {1,2,3,4} diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index a715e7e0b8..f967bc81ea 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -6917,7 +6917,7 @@ width_bucket_array_variable(Datum operand, * Only the first dimension is trimmed. */ Datum -trim_array(PG_FUNCTION_ARGS) +array_trim(PG_FUNCTION_ARGS) { ArrayType *v = PG_GETARG_ARRAYTYPE_P(0); int n = PG_GETARG_INT32(1); diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 1ec0d6f6b5..6f5b7c6a22 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -1732,9 +1732,12 @@ proname => 'width_bucket', prorettype => 'int4', proargtypes => 'anycompatible anycompatiblearray', prosrc => 'width_bucket_array' }, -{ oid => '6172', descr => 'remove last N elements of array', +{ oid => '6172', descr => 'deprecated; an alias for array_trim', proname => 'trim_array', prorettype => 'anyarray', - proargtypes => 'anyarray int4', prosrc => 'trim_array' }, + proargtypes => 'anyarray int4', prosrc => 'array_trim' }, +{ oid => '8140', descr => 'remove last N elements of array', + proname => 'array_trim', prorettype => 'anyarray', + proargtypes => 'anyarray int4', prosrc => 'array_trim' }, { oid => '6215', descr => 'shuffle array', proname => 'array_shuffle', provolatile => 'v', prorettype => 'anyarray', proargtypes => 'anyarray', prosrc => 'array_shuffle' }, diff --git a/src/test/regress/expected/arrays.out b/src/test/regress/expected/arrays.out index a6d81fd5f9..d819393d65 100644 --- a/src/test/regress/expected/arrays.out +++ b/src/test/regress/expected/arrays.out @@ -2626,15 +2626,15 @@ SELECT width_bucket(5, ARRAY[3, 4, NULL]); ERROR: thresholds array must not contain NULLs SELECT width_bucket(5, ARRAY[ARRAY[1, 2], ARRAY[3, 4]]); ERROR: thresholds must be one-dimensional array --- trim_array -SELECT arr, trim_array(arr, 2) +-- array_trim +SELECT arr, array_trim(arr, 2) FROM (VALUES ('{1,2,3,4,5,6}'::bigint[]), ('{1,2}'), ('[10:16]={1,2,3,4,5,6,7}'), ('[-15:-10]={1,2,3,4,5,6}'), ('{{1,10},{2,20},{3,30},{4,40}}')) v(arr); - arr | trim_array + arr | array_trim -------------------------------+----------------- {1,2,3,4,5,6} | {1,2,3,4} {1,2} | {} @@ -2643,11 +2643,11 @@ FROM {{1,10},{2,20},{3,30},{4,40}} | {{1,10},{2,20}} (5 rows) -SELECT trim_array(ARRAY[1, 2, 3], -1); -- fail +SELECT array_trim(ARRAY[1, 2, 3], -1); -- fail ERROR: number of elements to trim must be between 0 and 3 -SELECT trim_array(ARRAY[1, 2, 3], 10); -- fail +SELECT array_trim(ARRAY[1, 2, 3], 10); -- fail ERROR: number of elements to trim must be between 0 and 3 -SELECT trim_array(ARRAY[]::int[], 1); -- fail +SELECT array_trim(ARRAY[]::int[], 1); -- fail ERROR: number of elements to trim must be between 0 and 0 -- array_shuffle SELECT array_shuffle('{1,2,3,4,5,6}'::int[]) <@ '{1,2,3,4,5,6}'; diff --git a/src/test/regress/sql/arrays.sql b/src/test/regress/sql/arrays.sql index 47058dfde5..04af09f422 100644 --- a/src/test/regress/sql/arrays.sql +++ b/src/test/regress/sql/arrays.sql @@ -800,9 +800,9 @@ SELECT width_bucket('5'::text, ARRAY[3, 4]::integer[]); SELECT width_bucket(5, ARRAY[3, 4, NULL]); SELECT width_bucket(5, ARRAY[ARRAY[1, 2], ARRAY[3, 4]]); --- trim_array +-- array_trim -SELECT arr, trim_array(arr, 2) +SELECT arr, array_trim(arr, 2) FROM (VALUES ('{1,2,3,4,5,6}'::bigint[]), ('{1,2}'), @@ -810,9 +810,9 @@ FROM ('[-15:-10]={1,2,3,4,5,6}'), ('{{1,10},{2,20},{3,30},{4,40}}')) v(arr); -SELECT trim_array(ARRAY[1, 2, 3], -1); -- fail -SELECT trim_array(ARRAY[1, 2, 3], 10); -- fail -SELECT trim_array(ARRAY[]::int[], 1); -- fail +SELECT array_trim(ARRAY[1, 2, 3], -1); -- fail +SELECT array_trim(ARRAY[1, 2, 3], 10); -- fail +SELECT array_trim(ARRAY[]::int[], 1); -- fail -- array_shuffle SELECT array_shuffle('{1,2,3,4,5,6}'::int[]) <@ '{1,2,3,4,5,6}'; -- 2.47.0