Re: BUG #18051: char(N) and varchar(N) behave opposite to the documentation

From: Nicolas Gouteux <nicolas(dot)gouteux(at)sonarsource(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #18051: char(N) and varchar(N) behave opposite to the documentation
Date: 2023-08-09 14:28:55
Message-ID: CANyQZ-7-gPLVhmjPE7wbAESt7m_w_Gb-JVTr1ao12UmTJMiHNA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Just tried that on Oracle, and of course, the length is 10... (see pic
attached)
[image: image.png]

Nicolas Gouteux | Sonar

https://sonarsource.com
Are you using SonarLint <https://www.sonarlint.org> in your IDE?

On Wed, 9 Aug 2023 at 16:04, Nicolas Gouteux <
nicolas(dot)gouteux(at)sonarsource(dot)com> wrote:

> Hi
>
> Sorry, but I still do not get it:
> - char type adds padding up to its length
> - select length(charcol), char_length(charcoal)
> both yield 1
> - how can the length of a char(10) be different than 10 since is right
> padded?
> - I am pretty sure that Oracle/MS-SQL/Sybase would say that length is 10...
>
>
> Nicolas Gouteux | Sonar
>
> https://sonarsource.com
> Are you using SonarLint <https://www.sonarlint.org> in your IDE?
>
>
> On Wed, 9 Aug 2023 at 14:57, David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
> wrote:
>
>> On Wednesday, August 9, 2023, PG Bug reporting form <
>> noreply(at)postgresql(dot)org> wrote:
>>
>>> The following bug has been logged on the website:
>>>
>>> Bug reference: 18051
>>> Logged by: Nicolas Gouteux
>>> Email address: nicolas(dot)gouteux(at)sonarsource(dot)com
>>> PostgreSQL version: 13.7
>>> Operating system: Linux
>>> Description:
>>>
>>> create table if not exists ngx_char (
>>> charcol char(10) not null,
>>> varcharcol varchar(10) not null
>>> );
>>> truncate table ngx_char;
>>> insert into ngx_char (charcol, varcharcol) values ('A', 'A');
>>> insert into ngx_char (charcol, varcharcol) values ('A ', 'A ');
>>> select charcol || 'B', varcharcol || 'C' from ngx_char;
>>> select * from ngx_char where charcol = varcharcol;
>>>
>>> Output:
>>>
>>> ?column?,?column?
>>> AB,AC
>>> AB,A C
>>>
>>> This is very strange! Is it me?
>>
>>
>> This is working as designed and documented. The concatenation to text
>> removes the insignificant white space in char. There is no manipulation of
>> content for varchar.
>>
>> Just don’t use char. There is no good reason to deal with its implicit
>> behaviors.
>>
>> David J.
>>
>>
>

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message David Rowley 2023-08-09 14:37:48 Re: BUG #18051: char(N) and varchar(N) behave opposite to the documentation
Previous Message Nicolas Gouteux 2023-08-09 14:04:42 Re: BUG #18051: char(N) and varchar(N) behave opposite to the documentation