Subject: variable length arrays

From: [email-masked] (Ray R. Larson)
Date: Tue, 16 Mar 93 12:18:48 -0800

I have run into the same problem of no single element varying length
arrays. There is a simple fix:

in $(POSTGRESHOME)/src/backend/utils/adt (assumes new pre-release version)

diff arrayfuncs.cbak arrayfuncs.c
94c94
<     return(((nelems > 0 || seen_string) ? (nelems + 1) : 0));
---
>     return(((nelems > 0 || seen_string || ((nelems == 0) && (i>2))) (nelems+ 1) : 0));

That should do it.

Ray Larson

---

From: [email-masked] (Paul M. Aoki)
Date: Tue, 16 Mar 93 13:21:20 -0800

> >     return(((nelems > 0 || seen_string || ((nelems == 0) && (i>2))) (nelems
+ 1) : 0));

The code in 4.1 assumes that you quote your array elements in the case 
of a single item.  (This is documented ... somewhere...)  Otherwise, 
there is no way to tell a blank string from an empty array.  For example,
the test added by Ray correctly handles
	{hi mom}
(whereas the 4.1 code requires you to say
	{"hi mom"}
in this case).  However, Ray's test also assumes that
	{  }
is the same thing as
	{"  "}
instead of the empty array, which may or may not be what you want.
This can be especially confusing if you're using non-character types :-)

Personally, to be safe, I always quote array elements.  The current array
parsing code makes assumptions about leading white space and such...
--
  Paul M. Aoki  |  CS Div., Dept. of EECS, UCB  |  [email-masked]
                |  Berkeley, CA 94720           |  ...!uunet!ucbvax!aoki