Re: BUG #14800: substring produces different results with similar types

From: Francisco Olarte <folarte(at)peoplecall(dot)com>
To: kostin(dot)artem(at)gmail(dot)com
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14800: substring produces different results with similar types
Date: 2017-09-06 14:12:41
Message-ID: CA+bJJbza+Zhj_mq2ovFLkY_u_iqTCecqkbXhYmugA+rHWjiK5Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Kostin:

On Wed, Sep 6, 2017 at 3:21 PM, <kostin(dot)artem(at)gmail(dot)com> wrote:
> These two commands produce different results with similar types
> select substring(cast(' 2345 ' as character(16)), 1, 7) || '?',
> substring(cast(' 2345 ' as varchar(16)), 1, 7) || '?';
>
> " 2345?";" 2345 ?"
>
> Should it work in this way or not?

If you are not sure whether something is a bug, you should try asking
in the general list, to avoid noise.

Anyway, you may notice char() discards trailing blanks, varchar does not:

n=> select cast(' 2345 ' as character(16)) || '?';
?column?
----------
2345?
(1 row)

Plain char is STORED space padded and TRUNCATED if too long ( standard
required IIRC ), and trailing spaces are disregarded in many places,
such as when concatenating.

Francisco Olarte.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2017-09-06 14:51:02 Re: BUG #14800: substring produces different results with similar types
Previous Message Tom Lane 2017-09-06 13:32:34 Re: BUG #14799: SELECT * FROM transition_table in a statement-level trigger