Re: Bracket, brace, parenthesis - Mailing list pgsql-hackers

From Kyotaro Horiguchi
Subject Re: Bracket, brace, parenthesis
Date
Msg-id 20210528.152540.1337913142389747325.horikyota.ntt@gmail.com
Whole thread Raw
In response to Re: Bracket, brace, parenthesis  (Michael Paquier <michael@paquier.xyz>)
Responses Re: Bracket, brace, parenthesis
List pgsql-hackers
At Thu, 27 May 2021 21:08:46 +0900, Michael Paquier <michael@paquier.xyz> wrote in 
> On Thu, May 27, 2021 at 03:20:10PM +0900, Kyotaro Horiguchi wrote:
> > At Fri, 14 May 2021 10:04:57 -0400, Tom Lane <tgl@sss.pgh.pa.us> wrote in 
> >> +1.  I tend to write "square bracket" or "curly brace" when I want to
> >> be extra clear, but I think the bare terms are widely understood to
> >> have those meanings.
> > 
> > Thanks!  I think the message is new in 14 so we can fix it right
> > away. The attached is the version with a commit message added.
> 
> No objections from me to fix that on HEAD now for clarity, let's wait
> a bit and see if others have more comments.  You have missed an update
> of multirangetypes.out, by the way.

Mmm. Thanks. So the test doesn't a check for the case of trailing
garbage.  Looking the discussion about trailing garbage of interger
values, we might need one for the case.

The atached second file adds a test for trailing garbage for
multirangetype.sql and rangetype.sql.

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center
From 3c503f9a7982bc583b84876a3019a4a3a28209ca Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Date: Thu, 27 May 2021 15:01:44 +0900
Subject: [PATCH v2 1/2] Change confusing 'bracket' use to clearer wording

The current error message looks like this.

LINE 1: select '[1,3]'::int4multirange;
               ^
DETAIL:  Missing left bracket.

It is quite confusing when mentioning a string that contains both of
brackets"[]" and braces"{}".

We are using several kind of wordings point "{}" but the bare word
"brace" is clear enough here.
---
 src/backend/utils/adt/multirangetypes.c       | 4 ++--
 src/test/regress/expected/multirangetypes.out | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/backend/utils/adt/multirangetypes.c b/src/backend/utils/adt/multirangetypes.c
index 0b81649779..fbcc27d072 100644
--- a/src/backend/utils/adt/multirangetypes.c
+++ b/src/backend/utils/adt/multirangetypes.c
@@ -146,7 +146,7 @@ multirange_in(PG_FUNCTION_ARGS)
                 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                  errmsg("malformed multirange literal: \"%s\"",
                         input_str),
-                 errdetail("Missing left bracket.")));
+                 errdetail("Missing left brace.")));
 
     /* consume ranges */
     parse_state = MULTIRANGE_BEFORE_RANGE;
@@ -282,7 +282,7 @@ multirange_in(PG_FUNCTION_ARGS)
                 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                  errmsg("malformed multirange literal: \"%s\"",
                         input_str),
-                 errdetail("Junk after right bracket.")));
+                 errdetail("Junk after right brace.")));
 
     ret = make_multirange(mltrngtypoid, rangetyp, range_count, ranges);
     PG_RETURN_MULTIRANGE_P(ret);
diff --git a/src/test/regress/expected/multirangetypes.out b/src/test/regress/expected/multirangetypes.out
index 04953a5990..50f7c37b88 100644
--- a/src/test/regress/expected/multirangetypes.out
+++ b/src/test/regress/expected/multirangetypes.out
@@ -7,7 +7,7 @@ select ''::textmultirange;
 ERROR:  malformed multirange literal: ""
 LINE 1: select ''::textmultirange;
                ^
-DETAIL:  Missing left bracket.
+DETAIL:  Missing left brace.
 select '{,}'::textmultirange;
 ERROR:  malformed multirange literal: "{,}"
 LINE 1: select '{,}'::textmultirange;
-- 
2.27.0

From a04bb0e2cafec4d6cd254ff9d745795a438d811c Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Date: Fri, 28 May 2021 15:21:45 +0900
Subject: [PATCH v2 2/2] Add test cases for trailing garbage of (multi)range
 types.

---
 src/test/regress/expected/multirangetypes.out | 5 +++++
 src/test/regress/expected/rangetypes.out      | 5 +++++
 src/test/regress/sql/multirangetypes.sql      | 1 +
 src/test/regress/sql/rangetypes.sql           | 1 +
 4 files changed, 12 insertions(+)

diff --git a/src/test/regress/expected/multirangetypes.out b/src/test/regress/expected/multirangetypes.out
index 50f7c37b88..98ac592127 100644
--- a/src/test/regress/expected/multirangetypes.out
+++ b/src/test/regress/expected/multirangetypes.out
@@ -13,6 +13,11 @@ ERROR:  malformed multirange literal: "{,}"
 LINE 1: select '{,}'::textmultirange;
                ^
 DETAIL:  Expected range start.
+select '{(,)}.'::textmultirange;
+ERROR:  malformed multirange literal: "{(,)}."
+LINE 1: select '{(,)}.'::textmultirange;
+               ^
+DETAIL:  Junk after right brace.
 select '{[a,c),}'::textmultirange;
 ERROR:  malformed multirange literal: "{[a,c),}"
 LINE 1: select '{[a,c),}'::textmultirange;
diff --git a/src/test/regress/expected/rangetypes.out b/src/test/regress/expected/rangetypes.out
index e6ca99d43d..f6170db53a 100644
--- a/src/test/regress/expected/rangetypes.out
+++ b/src/test/regress/expected/rangetypes.out
@@ -9,6 +9,11 @@ ERROR:  malformed range literal: ""
 LINE 1: select ''::textrange;
                ^
 DETAIL:  Missing left parenthesis or bracket.
+select '(,).'::textrange;
+ERROR:  malformed range literal: "(,)."
+LINE 1: select '(,).'::textrange;
+               ^
+DETAIL:  Junk after right parenthesis or bracket.
 select '-[a,z)'::textrange;
 ERROR:  malformed range literal: "-[a,z)"
 LINE 1: select '-[a,z)'::textrange;
diff --git a/src/test/regress/sql/multirangetypes.sql b/src/test/regress/sql/multirangetypes.sql
index 692f2416d9..3cbebedcd4 100644
--- a/src/test/regress/sql/multirangetypes.sql
+++ b/src/test/regress/sql/multirangetypes.sql
@@ -7,6 +7,7 @@
 -- negative tests; should fail
 select ''::textmultirange;
 select '{,}'::textmultirange;
+select '{(,)}.'::textmultirange;
 select '{[a,c),}'::textmultirange;
 select '{,[a,c)}'::textmultirange;
 select '{-[a,z)}'::textmultirange;
diff --git a/src/test/regress/sql/rangetypes.sql b/src/test/regress/sql/rangetypes.sql
index cb5353de6f..3a3e1029e0 100644
--- a/src/test/regress/sql/rangetypes.sql
+++ b/src/test/regress/sql/rangetypes.sql
@@ -8,6 +8,7 @@ create type textrange as range (subtype=text, collation="C");
 
 -- negative tests; should fail
 select ''::textrange;
+select '(,).'::textrange;
 select '-[a,z)'::textrange;
 select '[a,z) - '::textrange;
 select '(",a)'::textrange;
-- 
2.27.0


pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: [HACKERS] logical decoding of two-phase transactions
Next
From: torikoshia
Date:
Subject: Re: RFC: Logging plan of the running query