From 5d5cf912bc28e8aea13d2e6689bb9e67f166a40e Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Wed, 5 May 1999 21:38:40 +0000 Subject: [PATCH] I have two patches for 6.5.0: arrayfuncs.patch fixes a small bug in my previous patches for arrays array-regress.patch adds _bpchar and _varchar to regression tests -- Massimo Dal Zotto --- src/backend/utils/adt/arrayfuncs.c | 10 ++++++++-- src/test/regress/expected/arrays.out | 14 +++++++------- src/test/regress/expected/create_misc.out | 9 +++++---- src/test/regress/expected/create_table.out | 4 +++- src/test/regress/sql/create_misc.sql | 9 +++++---- src/test/regress/sql/create_table.sql | 4 +++- 6 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index 8c5518bda3..948b709275 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.40 1999/05/03 23:48:26 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.41 1999/05/05 21:38:37 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -1336,10 +1336,16 @@ array_map(ArrayType *v, system_cache_lookup(retType, false, &typlen, &typbyval, &typdelim, &typelem, &proc, &typalign); - /* Allocate temporary array for new values */ ndim = ARR_NDIM(v); dim = ARR_DIMS(v); nitems = getNitems(ndim, dim); + + /* Check for empty array */ + if (nitems <= 0) { + return v; + } + + /* Allocate temporary array for new values */ values = (char **) palloc(nitems * sizeof(char *)); MemSet(values, 0, nitems * sizeof(char *)); diff --git a/src/test/regress/expected/arrays.out b/src/test/regress/expected/arrays.out index 92cfc94d21..b0869a9495 100644 --- a/src/test/regress/expected/arrays.out +++ b/src/test/regress/expected/arrays.out @@ -1,9 +1,9 @@ QUERY: SELECT * FROM arrtest; -a |b |c |d |e ------------+---------------+-------------+-----------------+------------- -{1,2,3,4,5}|{{{0,0},{1,2}}}|{} |{} | -{11,12,23} |{{3,4},{4,5}} |{"foobar"} |{{"elt1","elt2"}}|{"3.4","6.7"} -{} |{3,4} |{"foo","bar"}|{"bar","foo"} | +a |b |c |d |e |f |g +-----------+---------------+-------------+-----------------+-------------+-----------------+--------------- +{1,2,3,4,5}|{{{0,0},{1,2}}}|{} |{} | |{} |{} +{11,12,23} |{{3,4},{4,5}} |{"foobar"} |{{"elt1","elt2"}}|{"3.4","6.7"}|{"abc ","abcde"}|{"abc","abcde"} +{} |{3,4} |{"foo","bar"}|{"bar","foo"} | | | (3 rows) QUERY: SELECT arrtest.a[1], @@ -43,8 +43,8 @@ QUERY: SELECT * FROM arrtest WHERE arrtest.a[1] < 5 and arrtest.c = '{"foobar"}'::_name; -a|b|c|d|e --+-+-+-+- +a|b|c|d|e|f|g +-+-+-+-+-+-+- (0 rows) QUERY: SELECT arrtest.a[1:3], diff --git a/src/test/regress/expected/create_misc.out b/src/test/regress/expected/create_misc.out index 3382c85669..b64aac65cb 100644 --- a/src/test/regress/expected/create_misc.out +++ b/src/test/regress/expected/create_misc.out @@ -114,13 +114,14 @@ QUERY: INSERT INTO f_star (class, e) VALUES ('f', '-12'::int2); QUERY: INSERT INTO f_star (class, f) VALUES ('f', '(11111111,33333333),(22222222,44444444)'::polygon); QUERY: INSERT INTO f_star (class) VALUES ('f'); -QUERY: INSERT INTO arrtest (a[5], b[2][1][2], c, d) - VALUES ('{1,2,3,4,5}', '{{{},{1,2}}}', '{}', '{}'); +QUERY: INSERT INTO arrtest (a[5], b[2][1][2], c, d, f, g) + VALUES ('{1,2,3,4,5}', '{{{},{1,2}}}', '{}', '{}', '{}', '{}'); QUERY: UPDATE arrtest SET e[0] = '1.1'; QUERY: UPDATE arrtest SET e[1] = '2.2'; -QUERY: INSERT INTO arrtest (a, b[2][2][1], c, d, e) +QUERY: INSERT INTO arrtest (a, b[2][2][1], c, d, e, f, g) VALUES ('{11,12,23}', '{{3,4},{4,5}}', '{"foobar"}', - '{{"elt1", "elt2"}}', '{"3.4", "6.7"}'); + '{{"elt1", "elt2"}}', '{"3.4", "6.7"}', + '{"abc","abcdefgh"}', '{"abc","abcdefgh"}'); QUERY: INSERT INTO arrtest (a, b[1][2][2], c, d[2][1]) VALUES ('{}', '{3,4}', '{foo,bar}', '{bar,foo}'); QUERY: CREATE TABLE iportaltest ( diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.out index 7f3859da5d..91c1445475 100644 --- a/src/test/regress/expected/create_table.out +++ b/src/test/regress/expected/create_table.out @@ -131,7 +131,9 @@ QUERY: CREATE TABLE arrtest ( b int4[][][], c name[], d text[][], - e float8[] + e float8[], + f char(5)[], + g varchar(5)[] ); QUERY: CREATE TABLE hash_i4_heap ( seqno int4, diff --git a/src/test/regress/sql/create_misc.sql b/src/test/regress/sql/create_misc.sql index 495f94506f..6431614a30 100644 --- a/src/test/regress/sql/create_misc.sql +++ b/src/test/regress/sql/create_misc.sql @@ -198,16 +198,17 @@ INSERT INTO f_star (class) VALUES ('f'); -- 'e' is also a large object. -- -INSERT INTO arrtest (a[5], b[2][1][2], c, d) - VALUES ('{1,2,3,4,5}', '{{{},{1,2}}}', '{}', '{}'); +INSERT INTO arrtest (a[5], b[2][1][2], c, d, f, g) + VALUES ('{1,2,3,4,5}', '{{{},{1,2}}}', '{}', '{}', '{}', '{}'); UPDATE arrtest SET e[0] = '1.1'; UPDATE arrtest SET e[1] = '2.2'; -INSERT INTO arrtest (a, b[2][2][1], c, d, e) +INSERT INTO arrtest (a, b[2][2][1], c, d, e, f, g) VALUES ('{11,12,23}', '{{3,4},{4,5}}', '{"foobar"}', - '{{"elt1", "elt2"}}', '{"3.4", "6.7"}'); + '{{"elt1", "elt2"}}', '{"3.4", "6.7"}', + '{"abc","abcdefgh"}', '{"abc","abcdefgh"}'); INSERT INTO arrtest (a, b[1][2][2], c, d[2][1]) VALUES ('{}', '{3,4}', '{foo,bar}', '{bar,foo}'); diff --git a/src/test/regress/sql/create_table.sql b/src/test/regress/sql/create_table.sql index 7bf244b2bc..ad955290fa 100644 --- a/src/test/regress/sql/create_table.sql +++ b/src/test/regress/sql/create_table.sql @@ -178,7 +178,9 @@ CREATE TABLE arrtest ( b int4[][][], c name[], d text[][], - e float8[] + e float8[], + f char(5)[], + g varchar(5)[] ); CREATE TABLE hash_i4_heap (