Skip to content

Commit ebd194a

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 dbb1210 commit ebd194a

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/backend/utils/adt/geo_ops.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4596,8 +4596,8 @@ poly_path(PG_FUNCTION_ARGS)
45964596
/* circle_in - convert a string to internal form.
45974597
*
45984598
* External format: (center and radius of circle)
4599-
* "((f8,f8)<f8>)"
4600-
* also supports quick entry style "(f8,f8,f8)"
4599+
* "<(f8,f8),f8>"
4600+
* also supports quick entry style "f8,f8,f8"
46014601
*/
46024602
Datum
46034603
circle_in(PG_FUNCTION_ARGS)
@@ -4613,16 +4613,19 @@ circle_in(PG_FUNCTION_ARGS)
46134613
s = str;
46144614
while (isspace((unsigned char) *s))
46154615
s++;
4616-
if ((*s == LDELIM_C) || (*s == LDELIM))
4616+
if (*s == LDELIM_C)
4617+
depth++, s++;
4618+
else if (*s == LDELIM)
46174619
{
4618-
depth++;
4620+
/* If there are two left parens, consume the first one */
46194621
cp = (s + 1);
46204622
while (isspace((unsigned char) *cp))
46214623
cp++;
46224624
if (*cp == LDELIM)
4623-
s = cp;
4625+
depth++, s = cp;
46244626
}
46254627

4628+
/* pair_decode will consume parens around the pair, if any */
46264629
if (!pair_decode(s, &circle->center.x, &circle->center.y, &s))
46274630
ereport(ERROR,
46284631
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),

src/test/regress/expected/circle.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
--
44
CREATE TABLE CIRCLE_TBL (f1 circle);
55
INSERT INTO CIRCLE_TBL VALUES ('<(5,1),3>');
6-
INSERT INTO CIRCLE_TBL VALUES ('<(1,2),100>');
7-
INSERT INTO CIRCLE_TBL VALUES ('1,3,5');
8-
INSERT INTO CIRCLE_TBL VALUES ('((1,2),3)');
9-
INSERT INTO CIRCLE_TBL VALUES ('<(100,200),10>');
10-
INSERT INTO CIRCLE_TBL VALUES ('<(100,1),115>');
6+
INSERT INTO CIRCLE_TBL VALUES ('((1,2),100)');
7+
INSERT INTO CIRCLE_TBL VALUES (' 1 , 3 , 5 ');
8+
INSERT INTO CIRCLE_TBL VALUES (' ( ( 1 , 2 ) , 3 ) ');
9+
INSERT INTO CIRCLE_TBL VALUES (' ( 100 , 200 ) , 10 ');
10+
INSERT INTO CIRCLE_TBL VALUES (' < ( 100 , 1 ) , 115 > ');
1111
-- bad values
1212
INSERT INTO CIRCLE_TBL VALUES ('<(-100,0),-100>');
1313
ERROR: invalid input syntax for type circle: "<(-100,0),-100>"

src/test/regress/sql/circle.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ CREATE TABLE CIRCLE_TBL (f1 circle);
66

77
INSERT INTO CIRCLE_TBL VALUES ('<(5,1),3>');
88

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

11-
INSERT INTO CIRCLE_TBL VALUES ('1,3,5');
11+
INSERT INTO CIRCLE_TBL VALUES (' 1 , 3 , 5 ');
1212

13-
INSERT INTO CIRCLE_TBL VALUES ('((1,2),3)');
13+
INSERT INTO CIRCLE_TBL VALUES (' ( ( 1 , 2 ) , 3 ) ');
1414

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

17-
INSERT INTO CIRCLE_TBL VALUES ('<(100,1),115>');
17+
INSERT INTO CIRCLE_TBL VALUES (' < ( 100 , 1 ) , 115 > ');
1818

1919
-- bad values
2020

0 commit comments

Comments
 (0)