Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jnR1z-0000FS-Ih for pgsql-bugs@arkaria.postgresql.org; Mon, 22 Jun 2020 18:18:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jnR1y-0007de-66 for pgsql-bugs@arkaria.postgresql.org; Mon, 22 Jun 2020 18:18:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jnR1x-0007dX-W9 for pgsql-bugs@lists.postgresql.org; Mon, 22 Jun 2020 18:18:53 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jnR1v-0006aQ-LQ for pgsql-bugs@lists.postgresql.org; Mon, 22 Jun 2020 18:18:53 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 05MIInkC2083977; Mon, 22 Jun 2020 14:18:49 -0400 From: Tom Lane To: chetan.burande7@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16507: RTRIM function doesnt behave as expected for certain scenario In-reply-to: <16507-9f30407b2c52a573@postgresql.org> References: <16507-9f30407b2c52a573@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Mon, 22 Jun 2020 17:47:17 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2083975.1592849929.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 22 Jun 2020 14:18:49 -0400 Message-ID: <2083976.1592849929@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form 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