diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-11-19 01:50:08 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-11-19 01:50:08 +0000 |
commit | 1e9a1a70adc1f36d9ba8cd67ce974f777df7aafb (patch) | |
tree | 2f254673cf73e55c6f78bc45d6ae4ce25ea307b3 /src/backend/utils/adt/array_userfuncs.c | |
parent | 8685c472235b7a5bcc786f66ba9adde44e3d670c (diff) | |
download | postgresql-1e9a1a70adc1f36d9ba8cd67ce974f777df7aafb.tar.gz postgresql-1e9a1a70adc1f36d9ba8cd67ce974f777df7aafb.zip |
Change array_push and array_cat so that they retain the lower bound of
the array (for array_push) or higher-dimensional array (for array_cat)
rather than decrementing it as before. This avoids generating lower
bounds other than one for any array operation within the SQL spec. Per
recent discussion.
Interestingly, this seems to have been the original behavior, because
while updating the docs I noticed that a large fraction of relevant
examples were *wrong* for the old behavior and are now right. Is it
worth correcting this in the back-branch docs?
Diffstat (limited to 'src/backend/utils/adt/array_userfuncs.c')
-rw-r--r-- | src/backend/utils/adt/array_userfuncs.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/backend/utils/adt/array_userfuncs.c b/src/backend/utils/adt/array_userfuncs.c index 468e444e139..e1fc3f26db0 100644 --- a/src/backend/utils/adt/array_userfuncs.c +++ b/src/backend/utils/adt/array_userfuncs.c @@ -6,7 +6,7 @@ * Copyright (c) 2003-2005, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.17 2005/11/17 22:14:52 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.18 2005/11/19 01:50:08 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -152,6 +152,13 @@ array_push(PG_FUNCTION_ARGS) result = array_set(v, 1, &indx, newelem, isNull, -1, typlen, typbyval, typalign); + /* + * Readjust result's LB to match the input's. This does nothing in the + * append case, but it's the simplest way to implement the prepend case. + */ + if (ARR_NDIM(v) == 1) + ARR_LBOUND(result)[0] = ARR_LBOUND(v)[0]; + PG_RETURN_ARRAYTYPE_P(result); } @@ -305,7 +312,7 @@ array_cat(PG_FUNCTION_ARGS) { /* * resulting array has the second argument as the outer array, with - * the first argument appended to the front of the outer dimension + * the first argument inserted at the front of the outer dimension */ ndims = ndims2; dims = (int *) palloc(ndims * sizeof(int)); @@ -316,9 +323,6 @@ array_cat(PG_FUNCTION_ARGS) /* increment number of elements in outer array */ dims[0] += 1; - /* decrement outer array lower bound */ - lbs[0] -= 1; - /* make sure the added element matches our existing elements */ for (i = 0; i < ndims1; i++) { |