BUG #17664: The subsctring() function with the char() text type does not work correctly

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: snztim(at)yandex(dot)ru
Subject: BUG #17664: The subsctring() function with the char() text type does not work correctly
Date: 2022-10-26 09:00:58
Message-ID: 17664-cdd65e73c6ebcdc4@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 17664
Logged by: Evgenii Timofeev
Email address: snztim(at)yandex(dot)ru
PostgreSQL version: 15.0
Operating system: ALT Linux 10 (ALT Sisyphus 10.3.1)
Description:

Hi!

PostgreSQL version:
PostgreSQL 15.0 on x86_64-pc-linux-gnu, compiled by x86_64-alt-linux-gcc
(GCC) 10.3.1 20210703 (ALT Sisyphus 10.3.1-alt2), 64-bit

The situation is as follows:
First, we declare a char(10) text variable with the value 'abc' assigned to
it and a varchar(12) text variable within an anonymous block.
Within the body of the anonymous block we saddle a varchar(12) variable with
a char(10) variable and print the result.
The result will be valid data (example 1).

If we do the same, but add the substring() function to concat(), the result
will be incorrect (example 2).
As seen in example 2, the function substring(), which should have printed 4
characters, has printed only 3.

Please tell me why the result is not correct?

Example 1:
do $$
declare
M1 char(10) := 'abc';
M2 varchar(12);
begin
M2 := concat('-',M1,'-');
raise info '%', M2;
end;
$$;
Execution result: -abc -

Example 2:
do $$
declare
M1 char(10) := 'abc';
M2 varchar(12);
begin
M2 := concat('-',substring(M1,1,4),'-');
raise info '%', M2;
end;
$$;
Execution result: -abc-

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2022-10-27 10:42:52 BUG #17665: pg_stat_statements useless with variable number of parameters in IN close
Previous Message PG Bug reporting form 2022-10-26 08:59:52 BUG #17663: Connect to the database through jdbc, call the stored procedure containing the rollback statement,