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

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "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 02:00:52
Message-ID: CAKFQuwaqOhZvK1rndtTzJyFjsGEGVXrpceYF49bwX3mC0ADuVQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Monday, February 8, 2016, <dominik(dot)kosiorek(at)infobright(dot)com> wrote:

> The following bug has been logged on the website:
>
> Bug reference: 13934
> Logged by: Dominik Kosiorek
> Email address: dominik(dot)kosiorek(at)infobright(dot)com <javascript:;>
> PostgreSQL version: 9.2.2
> Operating system: Ubuntu 14
> Description:
>
> create table string1postgres(
> a1 int,
> a2 char(65),
> a3pattern char(15),
> a4field int
> )
> insert into string1postgres values(72,'abcd defg poir abcde m ert g d c v b
> gthb',' ',1);
>
> select split_part(a2,a3pattern,a4field) from string1postgres;
>
> -------------------
> the result of split part is:
> -------------------
> abcd defg poir abcde m ert g d c v b gthb
>
> -------------------
> instead of:
> -------------------
> abcd
>
> -------------------
> This defect is only with char type. On varchar result is correct.
>
>
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.

You may read the documentation for details:

http://www.postgresql.org/docs/9.5/static/datatype-character.html

And search the Internet for numerous postings as to why you should avoid
char.

Use to text or varchar instead.

David J.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2016-02-09 02:23:52 Re: BUG #13937: 'src' -> jsonb_each() -> jsonb_object() -> 'dst' does not recreate 'src' as valid jsonb
Previous Message David G. Johnston 2016-02-09 01:52:49 Re: BUG #13920: pg_try_advisory_xact_lock bigint trouble