Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 41a194f

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 75848bc commit 41a194f

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/backend/utils/adt/geo_ops.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -4604,8 +4604,8 @@ poly_path(PG_FUNCTION_ARGS)
46044604
/* circle_in - convert a string to internal form.
46054605
*
46064606
* External format: (center and radius of circle)
4607-
* "((f8,f8)<f8>)"
4608-
* also supports quick entry style "(f8,f8,f8)"
4607+
* "<(f8,f8),f8>"
4608+
* also supports quick entry style "f8,f8,f8"
46094609
*/
46104610
Datum
46114611
circle_in(PG_FUNCTION_ARGS)
@@ -4619,16 +4619,19 @@ circle_in(PG_FUNCTION_ARGS)
46194619
s = str;
46204620
while (isspace((unsigned char) *s))
46214621
s++;
4622-
if ((*s == LDELIM_C) || (*s == LDELIM))
4622+
if (*s == LDELIM_C)
4623+
depth++, s++;
4624+
else if (*s == LDELIM)
46234625
{
4624-
depth++;
4626+
/* If there are two left parens, consume the first one */
46254627
cp = (s + 1);
46264628
while (isspace((unsigned char) *cp))
46274629
cp++;
46284630
if (*cp == LDELIM)
4629-
s = cp;
4631+
depth++, s = cp;
46304632
}
46314633

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

46344637
if (*s == DELIM)

src/test/regress/expected/circle.out

+4-4
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

+4-4
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)