Return-Path: aoki
Received: by postgres.Berkeley.EDU (5.61/1.29)
	id AA14205; Tue, 16 Mar 93 13:21:19 -0800
Message-Id: <9303162121.AA14205@postgres.Berkeley.EDU>
From: aoki@postgres.berkeley.edu (Paul M. Aoki)
Subject: Re: variable length arrays
To: postgres@postgres.berkeley.edu
Sender: pg_adm@postgres.berkeley.edu
In-Reply-To: Your message of Tue, 16 Mar 93 12:18:48 -0800 
	     <9303162018.AA13666@postgres.Berkeley.EDU> 
Date: Tue, 16 Mar 93 13:21:20 -0800
Sender: aoki@postgres.Berkeley.EDU
X-Mts: smtp

ray@sherlock.Berkeley.EDU (Ray R. Larson) writes:
> 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));

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  |  aoki@postgres.Berkeley.EDU
                |  Berkeley, CA 94720           |  ...!uunet!ucbvax!aoki
