Skip to content

Commit 35d1eef

Browse files
committed
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/332c47fa-d951-7574-b5cc-a8f7f7201202@highgo.ca
1 parent 6e6b74a commit 35d1eef

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/backend/utils/adt/geo_ops.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4488,8 +4488,8 @@ poly_path(PG_FUNCTION_ARGS)
44884488
/* circle_in - convert a string to internal form.
44894489
*
44904490
* External format: (center and radius of circle)
4491-
* "((f8,f8)<f8>)"
4492-
* also supports quick entry style "(f8,f8,f8)"
4491+
* "<(f8,f8),f8>"
4492+
* also supports quick entry style "f8,f8,f8"
44934493
*/
44944494
Datum
44954495
circle_in(PG_FUNCTION_ARGS)
@@ -4503,16 +4503,19 @@ circle_in(PG_FUNCTION_ARGS)
45034503
s = str;
45044504
while (isspace((unsigned char) *s))
45054505
s++;
4506-
if ((*s == LDELIM_C) || (*s == LDELIM))
4506+
if (*s == LDELIM_C)
4507+
depth++, s++;
4508+
else if (*s == LDELIM)
45074509
{
4508-
depth++;
4510+
/* If there are two left parens, consume the first one */
45094511
cp = (s + 1);
45104512
while (isspace((unsigned char) *cp))
45114513
cp++;
45124514
if (*cp == LDELIM)
4513-
s = cp;
4515+
depth++, s = cp;
45144516
}
45154517

4518+
/* pair_decode will consume parens around the pair, if any */
45164519
pair_decode(s, &circle->center.x, &circle->center.y, &s, "circle", str);
45174520

45184521
if (*s == DELIM)

src/test/regress/expected/circle.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
SET extra_float_digits = -1;
77
CREATE TABLE CIRCLE_TBL (f1 circle);
88
INSERT INTO CIRCLE_TBL VALUES ('<(5,1),3>');
9-
INSERT INTO CIRCLE_TBL VALUES ('<(1,2),100>');
10-
INSERT INTO CIRCLE_TBL VALUES ('1,3,5');
11-
INSERT INTO CIRCLE_TBL VALUES ('((1,2),3)');
12-
INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10>');
9+
INSERT INTO CIRCLE_TBL VALUES ('((1,2),100)');
10+
INSERT INTO CIRCLE_TBL VALUES (' 1 , 3 , 5 ');
11+
INSERT INTO CIRCLE_TBL VALUES (' ( ( 1 , 2 ) , 3 ) ');
12+
INSERT INTO CIRCLE_TBL VALUES (' ( 100 , 200 ) , 10 ');
1313
INSERT INTO CIRCLE_TBL VALUES (' < ( 100 , 1 ) , 115 > ');
1414
INSERT INTO CIRCLE_TBL VALUES ('<(3,5),0>'); -- Zero radius
1515
INSERT INTO CIRCLE_TBL VALUES ('<(3,5),NaN>'); -- NaN radius

src/test/regress/sql/circle.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ CREATE TABLE CIRCLE_TBL (f1 circle);
1010

1111
INSERT INTO CIRCLE_TBL VALUES ('<(5,1),3>');
1212

13-
INSERT INTO CIRCLE_TBL VALUES ('<(1,2),100>');
13+
INSERT INTO CIRCLE_TBL VALUES ('((1,2),100)');
1414

15-
INSERT INTO CIRCLE_TBL VALUES ('1,3,5');
15+
INSERT INTO CIRCLE_TBL VALUES (' 1 , 3 , 5 ');
1616

17-
INSERT INTO CIRCLE_TBL VALUES ('((1,2),3)');
17+
INSERT INTO CIRCLE_TBL VALUES (' ( ( 1 , 2 ) , 3 ) ');
1818

19-
INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10>');
19+
INSERT INTO CIRCLE_TBL VALUES (' ( 100 , 200 ) , 10 ');
2020

2121
INSERT INTO CIRCLE_TBL VALUES (' < ( 100 , 1 ) , 115 > ');
2222

0 commit comments

Comments
 (0)