From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | elein <elein(at)varlena(dot)com>, Pavel Stehule <stehule(at)kix(dot)fsv(dot)cvut(dot)cz>, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org> |
Subject: | array concat, et al patch (was: [GENERAL] join of array) |
Date: | 2003-08-15 22:44:42 |
Message-ID: | 3F3D625A.503@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-patches |
Tom Lane wrote:
> Could you look at how big a change it'd be, anyway? Offhand I think it
> may just mean that the subscript-checking done in parse_expr.c needs to
> be done at runtime instead. Remember parse_expr should only be
> concerned about determining datatype, and for its purposes all arrays of
> a given element type are the same --- subscript checking should happen
> at runtime. (It seems likely that having an ndims field in ArrayExpr
> is inappropriate.)
The attached patch fixes code and regression tests for the following
(docs to follow once applied):
========================================================================
1) Array concatenation of equidimensional arrays:
========================================================================
regression=# select ARRAY[1,2] || ARRAY[3,4];
?column?
-----------
{1,2,3,4}
(1 row)
regression=# select ARRAY[[1],[2],[3]] || ARRAY[[4],[5]];
?column?
-----------------------
{{1},{2},{3},{4},{5}}
(1 row)
regression=# select ARRAY[[1,2],[2,3],[3,4]] || ARRAY[[4,5],[5,6]];
?column?
---------------------------------
{{1,2},{2,3},{3,4},{4,5},{5,6}}
(1 row)
========================================================================
2) Array literals or vars in ARRAY expressions:
========================================================================
regression=# create table arr(f1 int[], f2 int[]);
CREATE TABLE
regression=# insert into arr values (ARRAY[[1,2],[3,4]],ARRAY[[5,6],[7,8]]);
INSERT 2635544 1
regression=# select ARRAY[f1,f2] from arr;
array
-------------------------------
{{{1,2},{3,4}},{{5,6},{7,8}}}
(1 row)
regression=# select ARRAY['{{1,2},{3,4}}'::int[],'{{5,6},{7,8}}'::int[]];
array
-------------------------------
{{{1,2},{3,4}},{{5,6},{7,8}}}
(1 row)
========================================================================
3) Lower bound of outer array adjusted downward when an "element" (which
could itself be an array) is concatenated onto the front of an array:
========================================================================
regression=# create table arr(f1 int[]);
CREATE TABLE
regression=# insert into arr values ('{}');
INSERT 2635538 1
regression=# update arr set f1[-2] = 1;
UPDATE 1
regression=# select array_lower(f1,1) from arr;
array_lower
-------------
-2
(1 row)
regression=# select array_lower(f1 || 2, 1) from arr;
array_lower
-------------
-2
(1 row)
regression=# select array_lower(0 || f1, 1) from arr;
array_lower
-------------
-3
(1 row)
regression=# update arr set f1 = ARRAY[[1,2],[3,4]];
UPDATE 1
regression=# select array_lower(f1,1) from arr;
array_lower
-------------
1
(1 row)
regression=# select array_lower(f1 || ARRAY[5,6], 1) from arr;
array_lower
-------------
1
(1 row)
regression=# select array_lower(ARRAY[-1,0] || f1, 1) from arr;
array_lower
-------------
0
(1 row)
Compiles without warnings and passes all regression tests. If there are
no objections, please apply. As I mentioned above, docs to follow once
I'm sure what actually ends up being committed.
Joe
Attachment | Content-Type | Size |
---|---|---|
array-cat-fix.01.patch | text/plain | 17.6 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Jason Godden | 2003-08-15 23:33:51 | Re: summary and request |
Previous Message | Ron Johnson | 2003-08-15 22:24:02 | Re: Arrays and "goodness" in RDBMSs (was Re: join of |
From | Date | Subject | |
---|---|---|---|
Next Message | Jason Godden | 2003-08-15 23:33:51 | Re: summary and request |
Previous Message | Ron Johnson | 2003-08-15 22:24:02 | Re: Arrays and "goodness" in RDBMSs (was Re: join of |