From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Peter Eisentraut <peter_e(at)gmx(dot)net>, "Hackers (PostgreSQL)" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: array functions - request for opinions (was Re: [PATCHES] |
Date: | 2003-05-27 02:47:15 |
Message-ID: | 3ED2D1B3.5040508@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Tom Lane wrote:
> You would also have to assume that the subscript lower bound is one,
> which doesn't bother me but is an additional bit of state that has to
> appear out of nowhere. (In the assignment case you don't have to assume
> that, since the subscript tells you what to do.)
I've gotten this working for array concatenation and assignment.
Examples:
-- empty array concatenated with any element, return one element,
-- one-dimensional array, with lower bound set to 1
regression=# select '{}'::int4[] || 1;
?column?
----------
{1}
(1 row)
regression=# select 0 || '{}'::int4[];
?column?
----------
{0}
(1 row)
regression=# select array_dims(0 || '{}'::int4[]);
array_dims
------------
[1:1]
(1 row)
-- empty array concatenated with any non-empty, return the non-empty one
regression=# select '{}'::int4[] || array[[[1,2],[3,4]]];
?column?
-----------------
{{{1,2},{3,4}}}
(1 row)
-- concatenate two empty arrays, return empty array
regression=# select '{}'::int4[] || '{}'::int4[];
?column?
----------
{}
(1 row)
-- assignment to empty array: determine number
-- of dimensions and array subscripts based on those
-- given in the assignment statement
regression=# create table t(f float8[]);
CREATE TABLE
regression=# insert into t values('{}');
INSERT 2011035 1
regression=# update t set f[-2:2] = array[1,2,3,4,5];
UPDATE 1
regression=# select * from t;
f
-------------
{1,2,3,4,5}
(1 row)
regression=# select array_dims(f) from t;
array_dims
------------
[-2:2]
(1 row)
One question, should this work to create an empty array:
regression=# select array[];
ERROR: parser: parse error at or near "]" at character 14
or by analogy to '{}'::int4[]
regression=# select array[]::int4[];
ERROR: parser: parse error at or near "]" at character 14
Or is the current '{}'::int4[] syntax all we want/need?
Joe
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2003-05-27 02:50:27 | Re: [BUGS] Bug #928: server_min_messages (log_min_messages in CVS) |
Previous Message | Bruce Momjian | 2003-05-27 02:31:36 | Re: [BUGS] Bug #928: server_min_messages (log_min_messages in CVS) |