From: | "David E(dot) Wheeler" <david(at)kineticode(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Robert Haas <robertmhaas(at)gmail(dot)com>, Greg Stark <stark(at)enterprisedb(dot)com>, Sam Mason <sam(at)samason(dot)me(dot)uk>, pgsql-general(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: [HACKERS] string_to_array with empty input |
Date: | 2009-04-01 16:52:50 |
Message-ID: | 64185906-1AF5-4CFD-BA24-CE1D07B6E264@kineticode.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
On Apr 1, 2009, at 9:02 AM, Tom Lane wrote:
>> +1. I find this argument much more compelling than anything else
>> that's been offered up so far.
>
> Yeah. It seems to me that if you consider only the case where the
> array
> elements are text, there's a weak preference for considering '' to
> be a
> single empty string; but as soon as you think about any other
> datatype,
> there's a strong preference to consider it a zero-element list. So I
> too have come around to favor the latter interpretation. Do we have
> any remaining holdouts?
Well, I'd just point out that the return value of string_to_array() is
text[]. Thus, this is not a problem with string_to_array(), but a
casting problem from text[] to int[]. Making string_to_array() return
a NULL for this case to make casting simpler is addressing the problem
in the wrong place, IMHO. If I want to do this in Perl, for example,
I'd do something like this:
my @ints = grep { defined $_ && $_ ne '' } split ',', $string;
So I split the string into an array, and then remove unreasonable
values. This also allows me to set defaults:
my @ints = map { $_ || 0 } split ',', $string;
This ensures that I get the proper number of records in the example of
something like '1,2,,4'.
So I still think that string_to_array('', ',') should return '{""}',
and how casting is handled should be left to the user to flexibly
handle.
That said, I'm not seeing a simple function for modifying an array.
I'd have to write one for each specific case. :-(
Best,
David
From | Date | Subject | |
---|---|---|---|
Next Message | Scott Mead | 2009-04-01 16:59:53 | Re: [GENERAL] Re: [GENERAL] ERROR: XX001: could not read block 2354 of relation… |
Previous Message | Patrick Desjardins | 2009-04-01 16:32:03 | Re: [GENERAL] ERROR: XX001: could not read block 2354 of relation… |
From | Date | Subject | |
---|---|---|---|
Next Message | justin | 2009-04-01 17:05:04 | Re: [HACKERS] string_to_array with empty input |
Previous Message | Robert Haas | 2009-04-01 16:50:55 | Re: 8.4 open items list |