Re: BUG #16507: RTRIM function doesnt behave as expected for certain scenario

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: chetan(dot)burande7(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16507: RTRIM function doesnt behave as expected for certain scenario
Date: 2020-06-22 18:18:49
Message-ID: 2083976.1592849929@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Daniel Danzberger 2020-06-23 09:40:53 Re: BUG #15293: Stored Procedure Triggered by Logical Replication is Unable to use Notification Events
Previous Message PG Bug reporting form 2020-06-22 17:47:17 BUG #16507: RTRIM function doesnt behave as expected for certain scenario