Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5fae664

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/[email protected]
1 parent 5d79fc6 commit 5fae664

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
@@ -4525,8 +4525,8 @@ poly_path(PG_FUNCTION_ARGS)
45254525
/* circle_in - convert a string to internal form.
45264526
*
45274527
* External format: (center and radius of circle)
4528-
* "((f8,f8)<f8>)"
4529-
* also supports quick entry style "(f8,f8,f8)"
4528+
* "<(f8,f8),f8>"
4529+
* also supports quick entry style "f8,f8,f8"
45304530
*/
45314531
Datum
45324532
circle_in(PG_FUNCTION_ARGS)
@@ -4540,16 +4540,19 @@ circle_in(PG_FUNCTION_ARGS)
45404540
s = str;
45414541
while (isspace((unsigned char) *s))
45424542
s++;
4543-
if ((*s == LDELIM_C) || (*s == LDELIM))
4543+
if (*s == LDELIM_C)
4544+
depth++, s++;
4545+
else if (*s == LDELIM)
45444546
{
4545-
depth++;
4547+
/* If there are two left parens, consume the first one */
45464548
cp = (s + 1);
45474549
while (isspace((unsigned char) *cp))
45484550
cp++;
45494551
if (*cp == LDELIM)
4550-
s = cp;
4552+
depth++, s = cp;
45514553
}
45524554

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

45554558
if (*s == DELIM)

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)