Re: BUG #13934: wrong result of split_part with char value

From: Joe Conway <mail(at)joeconway(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "dominik(dot)kosiorek(at)infobright(dot)com" <dominik(dot)kosiorek(at)infobright(dot)com>
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #13934: wrong result of split_part with char value
Date: 2016-02-09 15:29:08
Message-ID: 56BA05C4.7010004@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 02/08/2016 06:00 PM, David G. Johnston wrote:
> On Monday, February 8, 2016, <dominik(dot)kosiorek(at)infobright(dot)com
> This calls for another round of "don't use char” advice...
>
> It is not a bug but a result of the fact that trailing white space in
> char values is able to be trimmed away thus leaving you the empty string
> and no splitting.

In other words, when you insert ' ' into string1postgres.a3pattern,
which is defined as char(15), the single space is trimmed leaving an
empty string:

test=# select '***' || a3pattern || '!!!' from string1postgres;
?column?
----------
***!!!
(1 row)

And if you feed an actual space to split_part(), it works as expected.

test=# select split_part(a2,' ',a4field) from string1postgres;
split_part
------------
abcd
(1 row)

HTH,

Joe

--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2016-02-09 15:46:37 Re: BUG #13937: 'src' -> jsonb_each() -> jsonb_object() -> 'dst' does not recreate 'src' as valid jsonb
Previous Message kurt 2016-02-09 14:42:01 BUG #13938: CAST error on Index "function must be immutable"