Re: [BUGS] BUG #14800: substring produces different results withsimilar types - Mailing list pgsql-bugs

From Francisco Olarte
Subject Re: [BUGS] BUG #14800: substring produces different results withsimilar types
Date
Msg-id CA+bJJbza+Zhj_mq2ovFLkY_u_iqTCecqkbXhYmugA+rHWjiK5Q@mail.gmail.com
Whole thread Raw
In response to [BUGS] BUG #14800: substring produces different results with similar types  (kostin.artem@gmail.com)
Responses Re: [BUGS] BUG #14800: substring produces different results with similar types
List pgsql-bugs
Kostin:

On Wed, Sep 6, 2017 at 3:21 PM,  <kostin.artem@gmail.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.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: [BUGS] BUG #14799: SELECT * FROM transition_table in a statement-level trigger
Next
From: Tom Lane
Date:
Subject: Re: [BUGS] BUG #14800: substring produces different results with similar types