From: Bruce Momjian <bruce@momjian.us>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: amutu@amutu.com
Cc: PostgreSQL-development <pgsql-hackers@postgreSQL.org>
Subject: Re: [BUGS] BUG #8335: trim() un-document behaviour
Date: Mon, 12 Aug 2013 10:11:44 -0400
Message-ID: <20130812141144.GA12510@momjian.us> (raw)
In-Reply-To: <20130809162359.GA3353@momjian.us>
References: <E1V2XgU-0003tb-Ii@wrigleys.postgresql.org>
<20130807161953.GZ11189@momjian.us>
<19166.1376060775@sss.pgh.pa.us>
<20130809162359.GA3353@momjian.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
On Fri, Aug 9, 2013 at 12:23:59PM -0400, Bruce Momjian wrote:
> Yes, I have thought about this some more and another problem is that
> rtrim/btrim/ltrim() use the source string first, so having trim() have
> the source string second when using a comma is very confusing, e.g.:
>
> -- with patch
> SELECT trim('x', 'xabcx');
> btrim
> -------
> abc
>
> -- btrim
> SELECT btrim('xabcx', 'x');
> btrim
> -------
> abc
>
> I think we can either document what we have, or remove the ability to
> use comma with trim(). If we go with documentation, it is going to look
> confusing as the optional modifier is going to be on the source string,
> e.g.:
>
> SELECT trim(both 'xabcx', 'x');
> btrim
> -------
> abc
>
> We could modify the grammar to force the modifier on the second
> argument, but that is more parser states for limited value.
[ moved to hackers ]
Based on my research, I am now proposing a new, attached patch which
eliminates comma in all places in TRIM, e.g. this is no longer valid
either:
SELECT trim(BOTH FROM 'abc', 'a');
btrim
-------
bc
(1 row)
I believe the flexible TRIM syntax was introduced when TRIM was added in
1997:
commit 570620c5698b0c76b26a3ec71692df29375cad16
Author: Thomas G. Lockhart <lockhart@fourpalms.org>
Date: Mon Sep 1 06:00:35 1997 +0000
Add SQL92 string handling features (SUBSTRING, TRIM, EXTRACT).
We would now only support the documented TRIM syntax.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackersAttachments:trim.diff (text/x-diff, 735B) downloaddiff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.ynew file mode 100644index 22e82ba..aa88cfb
*** a/src/backend/parser/gram.y
--- b/src/backend/parser/gram.y
*************** substr_from:
*** 11991,11999 ****
substr_for: FOR a_expr { $$ = $2; }
;
! trim_list: a_expr FROM expr_list { $$ = lappend($3, $1); }
! | FROM expr_list { $$ = $2; }
! | expr_list { $$ = $1; }
;
in_expr: select_with_parens
--- 11991,11999 ----
substr_for: FOR a_expr { $$ = $2; }
;
! trim_list: a_expr FROM a_expr { $$ = list_make2($3, $1); }
! | FROM a_expr { $$ = list_make1($2); }
! | a_expr { $$ = list_make1($1); }
;
in_expr: select_with_parens
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: bruce@momjian.us, tgl@sss.pgh.pa.us, amutu@amutu.com, pgsql-hackers@postgreSQL.org
Subject: Re: [BUGS] BUG #8335: trim() un-document behaviour
In-Reply-To: <20130812141144.GA12510@momjian.us>
References: <E1V2XgU-0003tb-Ii@wrigleys.postgresql.org> <20130807161953.GZ11189@momjian.us> <19166.1376060775@sss.pgh.pa.us> <20130809162359.GA3353@momjian.us> <20130812141144.GA12510@momjian.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