diff options
author | Tom Lane | 2020-04-08 00:50:02 +0000 |
---|---|---|
committer | Tom Lane | 2020-04-08 00:50:28 +0000 |
commit | 41a194f49177daf9348bfde2c42e85b806dcee31 (patch) | |
tree | 6d2508ab57f329e847cde5f7f7d787463ffcd743 | |
parent | 75848bc74411130ede23995d0ab1aefb12c4c4b0 (diff) |
Fix circle_in to accept "(x,y),r" as it's advertised to do.
Our documentation describes four allowed input syntaxes for circles,
but the regression tests tried only three ... with predictable
consequences. Remarkably, this has been wrong since the circle
datatype was added in 1997, but nobody noticed till now.
David Zhang, with some help from me
Discussion: https://postgr.es/m/[email protected]
-rw-r--r-- | src/backend/utils/adt/geo_ops.c | 13 | ||||
-rw-r--r-- | src/test/regress/expected/circle.out | 8 | ||||
-rw-r--r-- | src/test/regress/sql/circle.sql | 8 |
3 files changed, 16 insertions, 13 deletions
diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c index 71ee7f8f08..a7db783958 100644 --- a/src/backend/utils/adt/geo_ops.c +++ b/src/backend/utils/adt/geo_ops.c @@ -4604,8 +4604,8 @@ poly_path(PG_FUNCTION_ARGS) /* circle_in - convert a string to internal form. * * External format: (center and radius of circle) - * "((f8,f8)<f8>)" - * also supports quick entry style "(f8,f8,f8)" + * "<(f8,f8),f8>" + * also supports quick entry style "f8,f8,f8" */ Datum circle_in(PG_FUNCTION_ARGS) @@ -4619,16 +4619,19 @@ circle_in(PG_FUNCTION_ARGS) s = str; while (isspace((unsigned char) *s)) s++; - if ((*s == LDELIM_C) || (*s == LDELIM)) + if (*s == LDELIM_C) + depth++, s++; + else if (*s == LDELIM) { - depth++; + /* If there are two left parens, consume the first one */ cp = (s + 1); while (isspace((unsigned char) *cp)) cp++; if (*cp == LDELIM) - s = cp; + depth++, s = cp; } + /* pair_decode will consume parens around the pair, if any */ pair_decode(s, &circle->center.x, &circle->center.y, &s, "circle", str); if (*s == DELIM) diff --git a/src/test/regress/expected/circle.out b/src/test/regress/expected/circle.out index 218300f126..eb497a2384 100644 --- a/src/test/regress/expected/circle.out +++ b/src/test/regress/expected/circle.out @@ -6,10 +6,10 @@ SET extra_float_digits = -1; CREATE TABLE CIRCLE_TBL (f1 circle); INSERT INTO CIRCLE_TBL VALUES ('<(5,1),3>'); -INSERT INTO CIRCLE_TBL VALUES ('<(1,2),100>'); -INSERT INTO CIRCLE_TBL VALUES ('1,3,5'); -INSERT INTO CIRCLE_TBL VALUES ('((1,2),3)'); -INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10>'); +INSERT INTO CIRCLE_TBL VALUES ('((1,2),100)'); +INSERT INTO CIRCLE_TBL VALUES (' 1 , 3 , 5 '); +INSERT INTO CIRCLE_TBL VALUES (' ( ( 1 , 2 ) , 3 ) '); +INSERT INTO CIRCLE_TBL VALUES (' ( 100 , 200 ) , 10 '); INSERT INTO CIRCLE_TBL VALUES (' < ( 100 , 1 ) , 115 > '); INSERT INTO CIRCLE_TBL VALUES ('<(3,5),0>'); -- Zero radius INSERT INTO CIRCLE_TBL VALUES ('<(3,5),NaN>'); -- NaN radius diff --git a/src/test/regress/sql/circle.sql b/src/test/regress/sql/circle.sql index 7e582c6c29..170d6bee97 100644 --- a/src/test/regress/sql/circle.sql +++ b/src/test/regress/sql/circle.sql @@ -10,13 +10,13 @@ CREATE TABLE CIRCLE_TBL (f1 circle); INSERT INTO CIRCLE_TBL VALUES ('<(5,1),3>'); -INSERT INTO CIRCLE_TBL VALUES ('<(1,2),100>'); +INSERT INTO CIRCLE_TBL VALUES ('((1,2),100)'); -INSERT INTO CIRCLE_TBL VALUES ('1,3,5'); +INSERT INTO CIRCLE_TBL VALUES (' 1 , 3 , 5 '); -INSERT INTO CIRCLE_TBL VALUES ('((1,2),3)'); +INSERT INTO CIRCLE_TBL VALUES (' ( ( 1 , 2 ) , 3 ) '); -INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10>'); +INSERT INTO CIRCLE_TBL VALUES (' ( 100 , 200 ) , 10 '); INSERT INTO CIRCLE_TBL VALUES (' < ( 100 , 1 ) , 115 > '); |