From: Tom Lane <tgl@sss.pgh.pa.us>
To: chetan.burande7@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16507: RTRIM function doesnt behave as expected for certain scenario
Date: Mon, 22 Jun 2020 14:18:49 -0400
Message-ID: <2083976.1592849929@sss.pgh.pa.us> (raw)
In-Reply-To: <16507-9f30407b2c52a573@postgresql.org>
References: <16507-9f30407b2c52a573@postgresql.org>
PG Bug reporting form <noreply@postgresql.org> writes:
> I am trying to use RTIM function on a String (Column data) to remove some
> character/string from the right end.
> Example -
> select column_name, RTRIM(column_name, '-1') from table_name;
> In case of the first string, RTRIM is removing "1-1" instead of "-1".
> I expect it to remove "-1" as it did in other strings.
Your expectation is wrong, per the function's documentation:
Removes the longest string containing only characters in
'characters' (a space by default) from the end of 'string'.
The example is pretty explicit about this, too:
rtrim('testxxzx', 'xyz') → test
You could do what you want with regexp_replace() or the pattern-matching
variant of substring().
regards, tom lane
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: tgl@sss.pgh.pa.us, chetan.burande7@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16507: RTRIM function doesnt behave as expected for certain scenario
In-Reply-To: <2083976.1592849929@sss.pgh.pa.us>
* 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