Re: [HACKERS] string_to_array with empty input

From: justin <justin(at)emproshunts(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 17:05:04
Message-ID: 49D39EC0.3080608@emproshunts.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Tom Lane wrote:
<blockquote cite="mid:6569(dot)1238601738(at)sss(dot)pgh(dot)pa(dot)us" type="cite">
<pre wrap="">Robert Haas <a class="moz-txt-link-rfc2396E" href="mailto:robertmhaas(at)gmail(dot)com">&lt;robertmhaas(at)gmail(dot)com&gt;</a> writes:
</pre>
<blockquote type="cite">
<pre wrap="">On Tue, Mar 31, 2009 at 10:44 AM, Greg Stark <a class="moz-txt-link-rfc2396E" href="mailto:stark(at)enterprisedb(dot)com">&lt;stark(at)enterprisedb(dot)com&gt;</a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On Tue, Mar 31, 2009 at 3:42 PM, Sam Mason <a class="moz-txt-link-rfc2396E" href="mailto:sam(at)samason(dot)me(dot)uk">&lt;sam(at)samason(dot)me(dot)uk&gt;</a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">string_to_array('',',')::INT[] &nbsp;=&gt; invalid input syntax for integer: ""
</pre>
</blockquote>
<pre wrap="">Oof. That's a good point.
</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->
</pre>
<blockquote type="cite">
<pre wrap="">+1. I find this argument much more compelling than anything else
that's been offered up so far.
</pre>
</blockquote>
<pre wrap=""><!---->
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?

regards, tom lane
</pre>
</blockquote>
<br>
I'm still a hold out,&nbsp; We are taking a string putting it into a array
based on a delimiter.&nbsp; That is very simple and straight forward.&nbsp; Yet
many argue if we want to cast this into another data type the function
should deal with in limited cases.&nbsp; <br>
<br>
string_to_array('',',')::INT[]&nbsp; works as proposed <br>
<br>
But <br>
string_to_array(',,,', ',' )::INT[]&nbsp;&nbsp; Fails <br>
or<br>
string_to_array('1,2,,4', ',' )::INT[] Fails .<br>
<br>
<br>
I'm trying to understand the difference between a empty string to a
string with&nbsp; many blank entries between&nbsp; the delimiter.&nbsp;&nbsp;&nbsp; <br>
Consider&nbsp;&nbsp;
',,,,,,'&nbsp; = ''&nbsp; once the delimiter is removed .&nbsp; Yet Seven zero length
entries were passed.&nbsp; How is that going to
be handled????&nbsp; <br>
<br>
In one case it works and yet other cases it fails.&nbsp; This is
inconsistent behavior.&nbsp; Unless all zero length strings are removed or
are treated as NULLs&nbsp; I can't see how casting to another type is going
to work.<br>
<br>
If zero length strings are treated as NULLs this creates idea that zero
length strings are = to NULLs. <br>
<br>
The input is a string and the output is text[],&nbsp; casting to another
data type is error prone and should be handled by the programmer.&nbsp; <br>
</body>
</html>

Attachment Content-Type Size
unknown_filename text/html 3.0 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2009-04-01 17:06:40 Re: [GENERAL] Re: [GENERAL] ERROR: XX001: could not read block 2354 of relation…
Previous Message Patrick Desjardins 2009-04-01 17:03:43 Re: [GENERAL] Re: [GENERAL] ERROR: XX001: could not read block 2354 of relation…

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2009-04-01 17:09:38 Re: [HACKERS] string_to_array with empty input
Previous Message David E. Wheeler 2009-04-01 16:52:50 Re: [HACKERS] string_to_array with empty input