pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedERROR: invalid input syntax for type circle
4+ messages / 2 participants
[nested] [flat]
Commits from this thread:
2020-04-08 35d1eefb29 5fae664101 049e9f48e9 ebd194ac58 4c7a311a2d 41a194f491 Fix circle_in to accept "(x,y),r" as it's advertised to do.
* ERROR: invalid input syntax for type circle
@ 2020-04-06 21:12 David Zhang <david.zhang@highgo.ca>
2020-04-06 22:16 ` Re: ERROR: invalid input syntax for type circle Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 4+ messages in thread
From: David Zhang @ 2020-04-06 21:12 UTC (permalink / raw)
To: pgsql-hackers@postgresql.org, David Zhang <david.zhang@highgo.ca>
Hi,
I got an error when I was trying to insert a circle using the syntax
(the 3rd one) specified in the latest document.
https://www.postgresql.org/docs/current/datatype-geometric.html#DATATYPE-CIRCLE
< ( x , y ) , r >
( ( x , y ) , r )
( x , y ) , r
x , y , r
Here is how to reproduce it.
CREATE TABLE tbl_circle(id serial PRIMARY KEY, a circle);
INSERT INTO tbl_circle(a) VALUES('( 1 , 1 ) , 5'::circle );
ERROR: invalid input syntax for type circle: "( 1 , 1 ) , 5"
LINE 1: INSERT INTO tbl_circle(a) VALUES('( 1 , 1 ) , 5'::circle );
I made a little change in the "circle_in" function, and then I can enter
a circle using the 3rd way.
INSERT INTO tbl_circle(a) VALUES('( 1 , 1 ) , 5'::circle );
INSERT 0 1
The fix does generate the same output as the other three ways.
INSERT INTO tbl_circle(a) VALUES( '< ( 1 , 1 ) , 5 >'::circle );
INSERT INTO tbl_circle(a) VALUES( '( ( 1 , 1 ) , 5 )'::circle );
INSERT INTO tbl_circle(a) VALUES( '1 , 1 , 5'::circle );
select * from tbl_circle;
id | a
----+-----------
1 | <(1,1),5>
2 | <(1,1),5>
3 | <(1,1),5>
4 | <(1,1),5>
(4 rows)
Sor far, no error found during the "make check".
The patch based on tag "REL_12_2" is attached.
--
David
Software Engineer
Highgo Software Inc. (Canada)
www.highgo.ca
Attachments:
circle-in-input-format-fix.patch (text/plain, 434B) download
diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c
index 373784fcc1..6efd5bc1f2 100644
--- a/src/backend/utils/adt/geo_ops.c
+++ b/src/backend/utils/adt/geo_ops.c
@@ -4528,7 +4528,7 @@ circle_in(PG_FUNCTION_ARGS)
while (depth > 0)
{
- if ((*s == RDELIM) || ((*s == RDELIM_C) && (depth == 1)))
+ if ((*s == RDELIM) || (((*s == RDELIM_C) || (*s == '\0')) && (depth == 1)))
{
depth--;
s++;
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: ERROR: invalid input syntax for type circle
2020-04-06 21:12 ERROR: invalid input syntax for type circle David Zhang <david.zhang@highgo.ca>
@ 2020-04-06 22:16 ` Tom Lane <tgl@sss.pgh.pa.us>
2020-04-07 00:44 ` Re: ERROR: invalid input syntax for type circle David Zhang <david.zhang@highgo.ca>
0 siblings, 1 reply; 4+ messages in thread
From: Tom Lane @ 2020-04-06 22:16 UTC (permalink / raw)
To: David Zhang <david.zhang@highgo.ca>; +Cc: pgsql-hackers
David Zhang <david.zhang@highgo.ca> writes:
> I got an error when I was trying to insert a circle using the syntax
> (the 3rd one) specified in the latest document.
Hm. Presumably, that has never worked, and we've had no complaints
to date. I'm halfway inclined to treat it as a documentation bug
and remove the claim that it works.
> The patch based on tag "REL_12_2" is attached.
This patch looks extremely dangerous to me, because it'll allow "s"
to get incremented past the ending nul character ... and then the
code will proceed to keep scanning, which at best is useless and
at worst will end in a core dump.
What actually looks wrong to me in this code is the initial bit
if ((*s == LDELIM_C) || (*s == LDELIM))
{
depth++;
cp = (s + 1);
while (isspace((unsigned char) *cp))
cp++;
if (*cp == LDELIM)
s = cp;
}
If the first test triggers but it doesn't then find a following
paren, then it's incremented depth without moving s, which seems
certain to end badly. Perhaps the correct fix is like
if (*s == LDELIM_C)
depth++, s++;
else if (*s == LDELIM)
{
/* If there are two left parens, consume the first one */
cp = (s + 1);
while (isspace((unsigned char) *cp))
cp++;
if (*cp == LDELIM)
depth++, s = cp;
}
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: ERROR: invalid input syntax for type circle
2020-04-06 21:12 ERROR: invalid input syntax for type circle David Zhang <david.zhang@highgo.ca>
2020-04-06 22:16 ` Re: ERROR: invalid input syntax for type circle Tom Lane <tgl@sss.pgh.pa.us>
@ 2020-04-07 00:44 ` David Zhang <david.zhang@highgo.ca>
2020-04-08 00:51 ` Re: ERROR: invalid input syntax for type circle Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 4+ messages in thread
From: David Zhang @ 2020-04-07 00:44 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-hackers
Hi Tom,
Thanks for the review.
Generated a new patch v2 (attached) following your suggestion and
performed the same test again. The test results looks good including the
"make check".
On 2020-04-06 3:16 p.m., Tom Lane wrote:
> David Zhang <david.zhang@highgo.ca> writes:
>> I got an error when I was trying to insert a circle using the syntax
>> (the 3rd one) specified in the latest document.
> Hm. Presumably, that has never worked, and we've had no complaints
> to date. I'm halfway inclined to treat it as a documentation bug
> and remove the claim that it works.
>
>> The patch based on tag "REL_12_2" is attached.
> This patch looks extremely dangerous to me, because it'll allow "s"
> to get incremented past the ending nul character ... and then the
> code will proceed to keep scanning, which at best is useless and
> at worst will end in a core dump.
>
> What actually looks wrong to me in this code is the initial bit
>
> if ((*s == LDELIM_C) || (*s == LDELIM))
> {
> depth++;
> cp = (s + 1);
> while (isspace((unsigned char) *cp))
> cp++;
> if (*cp == LDELIM)
> s = cp;
> }
>
> If the first test triggers but it doesn't then find a following
> paren, then it's incremented depth without moving s, which seems
> certain to end badly. Perhaps the correct fix is like
>
> if (*s == LDELIM_C)
> depth++, s++;
> else if (*s == LDELIM)
> {
> /* If there are two left parens, consume the first one */
> cp = (s + 1);
> while (isspace((unsigned char) *cp))
> cp++;
> if (*cp == LDELIM)
> depth++, s = cp;
> }
>
> regards, tom lane
--
David
Software Engineer
Highgo Software Inc. (Canada)
www.highgo.ca
Attachments:
circle-in-input-format-fix-v2.patch (text/plain, 680B) download
diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c
index 373784f..c69844e 100644
--- a/src/backend/utils/adt/geo_ops.c
+++ b/src/backend/utils/adt/geo_ops.c
@@ -4503,14 +4503,16 @@ 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(s, &circle->center.x, &circle->center.y, &s, "circle", str);
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: ERROR: invalid input syntax for type circle
2020-04-06 21:12 ERROR: invalid input syntax for type circle David Zhang <david.zhang@highgo.ca>
2020-04-06 22:16 ` Re: ERROR: invalid input syntax for type circle Tom Lane <tgl@sss.pgh.pa.us>
2020-04-07 00:44 ` Re: ERROR: invalid input syntax for type circle David Zhang <david.zhang@highgo.ca>
@ 2020-04-08 00:51 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 4+ messages in thread
From: Tom Lane @ 2020-04-08 00:51 UTC (permalink / raw)
To: David Zhang <david.zhang@highgo.ca>; +Cc: pgsql-hackers
David Zhang <david.zhang@highgo.ca> writes:
> Generated a new patch v2 (attached) following your suggestion and
> performed the same test again. The test results looks good including the
> "make check".
Pushed, with some work on the regression tests so this doesn't get
busted again.
regards, tom lane
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2020-04-08 00:51 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-04-06 21:12 ERROR: invalid input syntax for type circle David Zhang <david.zhang@highgo.ca>
2020-04-06 22:16 ` Tom Lane <tgl@sss.pgh.pa.us>
2020-04-07 00:44 ` David Zhang <david.zhang@highgo.ca>
2020-04-08 00:51 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox