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

Поиск
Список
Период
Сортировка
От PG Bug reporting form
Тема BUG #18051: char(N) and varchar(N) behave opposite to the documentation
Дата
Msg-id 18051-3d2890ce9127a33a@postgresql.org
обсуждение исходный текст
Ответы Re: BUG #18051: char(N) and varchar(N) behave opposite to the documentation  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-bugs
The following bug has been logged on the website:

Bug reference:      18051
Logged by:          Nicolas Gouteux
Email address:      nicolas.gouteux@sonarsource.com
PostgreSQL version: 13.7
Operating system:   Linux
Description:

Hi

Since SQL inception, char(N) dataype is supposed to add padding blanks up to
N characters, whereas varchar(N) is supposed to truncate extra trailing
white spaces.

This is confirmed by the documentation:
If the string to be stored is shorter than the declared length, values of
type character will be space-padded
https://www.postgresql.org/docs/13/datatype-character.html

However, the following snippet exhibits the exact opposite behavior:

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?

Thanks


В списке pgsql-bugs по дате отправления:

Предыдущее
От: "Euler Taveira"
Дата:
Сообщение: Re: pg_restore 14 skips ACL COLUMN when --schema is used
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: BUG #18051: char(N) and varchar(N) behave opposite to the documentation