Re: array support patch phase 1 patch

From: Joe Conway <mail(at)joeconway(dot)com>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: array support patch phase 1 patch
Date: 2003-05-29 05:39:44
Message-ID: 3ED59D20.9030501@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

Joe Conway wrote:
> Joe Conway wrote:
>
>> Attached is an updated version of the doc patch along with the
>> addition of two new functions, as previously discussed:
>>
>> - str_to_array(str TEXT, delim TEXT) returns TEXT[]
>> - array_to_str(array ANYARRAY, delim TEXT) returns TEXT
>>
>> The patch is fairly large because:
>>
>> 1. the documentation part of it is large
>> 2. I moved some static functions around and made them accessible so
>> that I could use them in implementing the two functions.
>>
>> It passes all regression tests, and as mentioned above includes
>> documentation.
>>
>> If there are no objections, please apply.
>
>
> The attached is an update to the one above, with the following additions
> (recommended by Tom here -
> http://archives.postgresql.org/pgsql-patches/2003-04/msg00030.php)
>
> 1. array_eq() now applies the element type's equality operator on an
> element-by-element basis.
> 2. applied Tom's cache lookup results caching technique in arrayfuncs.c,
> array_userfuncs.c, and in the new functions in varlena.c.
>
> Still passes all regression tests. No additional doc updates needed for
> this one. If there are no objections, please apply.
>

This attached patch includes all of the above, with the following changes:

1. array_type_coerce() fixes discussed off list last weekend while the
list was mostly down.
2. empty array element and slice assignment, and empty array
concatenation as recently discussed on HACKERS.
3. Aggregates can now use polymorphic functions and be polymorphic
themselves (examples below)
4. removes array_accum function and documentation per recent discussions

I specifically did not change the spelling of the term
multi-dimensional/multidimensional -- I'd suggest we agree on one way
and be consistent, but I'd really rather not hold up this patch for that
as it is getting tough to stay in sync with cvs (had a backend function
disappear from under me just today).

I also left singleton_array, array_assign, and array_subscript in place
and documented. I'd still like to see them stay (there was a request on
GENERAL this afternoon that could have used singleton_array as probably
the most simple solution, although undoubtedly they could have kludged
it by concatenating to an empty array). But, again, I'd rather see this
patch committed, so if need be, please rip them out.

Here are some examples of the polymorphic aggregates:

create table t(f1 int, f2 int[], f3 text);
insert into t values(1,array[1],'a');
insert into t values(1,array[11],'b');
insert into t values(1,array[111],'c');
insert into t values(2,array[2],'a');
insert into t values(2,array[22],'b');
insert into t values(2,array[222],'c');
insert into t values(3,array[3],'a');
insert into t values(3,array[3],'b');

CREATE AGGREGATE myagg2
(
BASETYPE = int4,
SFUNC = array_append,
STYPE = int4[],
INITCOND = '{}'
);

CREATE AGGREGATE myagg3
(
BASETYPE = anyelement,
SFUNC = array_append,
STYPE = anyarray,
INITCOND = '{}'
);

CREATE AGGREGATE myagg4
(
BASETYPE = anyarray,
SFUNC = array_cat,
STYPE = anyarray,
INITCOND = '{}'
);

regression=# select f3, myagg2(f1) from t group by f3;
f3 | myagg2
----+---------
b | {1,2,3}
a | {1,2,3}
c | {1,2}
(3 rows)

regression=# select f3, myagg3(f1) from t group by f3;
f3 | myagg3
----+---------
b | {1,2,3}
a | {1,2,3}
c | {1,2}
(3 rows)

regression=# select f1, myagg3(f3) from t group by f1;
f1 | myagg3
----+---------
1 | {a,b,c}
3 | {a,b}
2 | {a,b,c}
(3 rows)

regression=# select f3, myagg4(f2) from t group by f3;
f3 | myagg4
----+-----------------
b | {{11},{22},{3}}
a | {{1},{2},{3}}
c | {{111},{222}}
(3 rows)

And assignment to an empty array:

regression=# insert into t values(4,'{}','d');
INSERT 2000865 1
regression=# update t set f2[2][4][6] = 42 where f1 = 4;
UPDATE 1
regression=# select * from t where f1 = 4;
f1 | f2 | f3
----+----------+----
4 | {{{42}}} | d
(1 row)

regression=# select array_dims(f2) from t where f1 = 4;
array_dims
-----------------
[2:2][4:4][6:6]
(1 row)

All 90 regression tests passed. More doc updates are needed based on
these changes, but I'd like to do those after the feature freeze if I
may. Please apply.

thanks,

Joe

Attachment Content-Type Size
array-phase2.19.patch text/plain 108.3 KB

In response to

Browse pgsql-patches by date

  From Date Subject
Next Message Fernando Nasser 2003-05-29 13:54:35 JDBC: One more autocommit use to work around
Previous Message Barry Lind 2003-05-29 04:53:32 Re: [PATCHES] JDBC: Wrong type