Hi,

I’m playing with pg_plan_advice and found a small issue.

PG supports underscores between digits; for example, 1_0 is parsed as 10:
```
evantest=# SELECT 1_0;
 ?column?
----------
       10
(1 row)
```

pg_plan_advice seems to intend to support the same syntax, based on 
pgpa_scanner.l:
```
decdigit                [0-9]
decinteger              {decdigit}(_?{decdigit})*
``` 

But it then uses strtoint() to parse the token, so an underscore causes a parse 
error:
```
evantest=# SET pg_plan_advice.advice = 'SEQ_SCAN(x#1_0)';
ERROR:  invalid value for parameter "pg_plan_advice.advice": "SEQ_SCAN(x#1_0)"
DETAIL:  Could not parse advice: integer out of range at or near "1_0"
```

The attached patch fixes this by using pg_strtoint32_safe() in the same way as 
the core scanner. With the fix, 1_0 works:
```
evantest=# SET pg_plan_advice.advice = 'SEQ_SCAN(x#1_0)';
SET
```

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/




Attachment: v1-0001-Fix-parsing-of-underscores-in-pg_plan_advice-occu.patch
Description: Binary data

Reply via email to