Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V8sqk-0001sF-1w for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Aug 2013 14:11:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V8sqj-0008QO-99 for pgsql-hackers@arkaria.postgresql.org; Mon, 12 Aug 2013 14:11:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V8sqi-0008QG-8h for pgsql-hackers@postgreSQL.org; Mon, 12 Aug 2013 14:11:56 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V8sqZ-0003nw-ST for pgsql-hackers@postgreSQL.org; Mon, 12 Aug 2013 14:11:55 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1V8sqW-0007N6-7Z; Mon, 12 Aug 2013 10:11:44 -0400 Date: Mon, 12 Aug 2013 10:11:44 -0400 From: Bruce Momjian To: Tom Lane Cc: amutu@amutu.com, PostgreSQL-development Subject: Re: [BUGS] BUG #8335: trim() un-document behaviour Message-ID: <20130812141144.GA12510@momjian.us> References: <20130807161953.GZ11189@momjian.us> <19166.1376060775@sss.pgh.pa.us> <20130809162359.GA3353@momjian.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="UugvWAfsgieZRqgk" Content-Disposition: inline In-Reply-To: <20130809162359.GA3353@momjian.us> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -4.7 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --UugvWAfsgieZRqgk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 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 http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. + --UugvWAfsgieZRqgk Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="trim.diff" diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y new file mode 100644 index 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 --UugvWAfsgieZRqgk Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --UugvWAfsgieZRqgk--