From: | Robert Haas <robertmhaas(at)gmail(dot)com> |
---|---|
To: | "David E(dot) Wheeler" <david(at)kineticode(dot)com> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, 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 19:19:23 |
Message-ID: | 603c8f070904011219x4d3db5d8lc72be812a2580800@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
On Wed, Apr 1, 2009 at 12:52 PM, David E. Wheeler <david(at)kineticode(dot)com> wrote:
> 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;
I've written code that looks a whole lot like this myself, but there's
no easy way to do that in SQL. SQL, in particular, lacks closures, so
grep {} and map {} don't exist. I really, really wish they did, but I
believe that our type system is too woefully pathetic to be up to the
job. So it seems to me that arguing that SQL (which lacks those
primitives) should match Perl (which has them) isn't really getting us
anywhere.
> 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'.
I can't see that there's any way to do this in SQL regardless of how
we define this operation.
...Robert
From | Date | Subject | |
---|---|---|---|
Next Message | Duco Fijma | 2009-04-01 19:26:33 | %r in restore_command? |
Previous Message | Sam Mason | 2009-04-01 19:17:50 | Re: [HACKERS] string_to_array with empty input |
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2009-04-01 19:28:59 | Re: [HACKERS] string_to_array with empty input |
Previous Message | Sam Mason | 2009-04-01 19:17:50 | Re: [HACKERS] string_to_array with empty input |