pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: snztim@yandex.ru
Subject: BUG #17664: The subsctring() function with the char() text type does not work correctly
Date: Wed, 26 Oct 2022 09:00:58 +0000
Message-ID: <17664-cdd65e73c6ebcdc4@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      17664
Logged by:          Evgenii Timofeev
Email address:      snztim@yandex.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-



view thread (2+ messages)  latest in thread

Message-ID: <17664-cdd65e73c6ebcdc4@postgresql.org>
Permalink:  ../17664-cdd65e73c6ebcdc4@postgresql.org/
Also on:    postgresql.org/message-id/17664-cdd65e73c6ebcdc4@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, snztim@yandex.ru
  Subject: Re: BUG #17664: The subsctring() function with the char() text type does not work correctly
  In-Reply-To: <17664-cdd65e73c6ebcdc4@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox