pg_plan_advice: fix parsing underscore in numbers - Mailing list pgsql-hackers

From Chao Li
Subject pg_plan_advice: fix parsing underscore in numbers
Date
Msg-id 22E2ECE0-B768-43D5-8575-61C3EBC2E4E8@gmail.com
Whole thread
List pgsql-hackers
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

pgsql-hackers by date:

Previous
From: Ian Lawrence Barwick
Date:
Subject: Re: doc: clarify wal_sender_shutdown_timeout behavior for small values
Next
From: Fujii Masao
Date:
Subject: Re: [PATCH] Don't call ereport(ERROR) from recovery target GUC assign hooks