| From: | Yuefei Shi <shiyuefei1004(at)gmail(dot)com> |
|---|---|
| To: | Heikki Linnakangas <hlinnaka(at)iki(dot)fi> |
| Cc: | "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: Use strtoi64() in pgbench, replacing its open-coded implementation |
| Date: | 2025-11-20 00:58:30 |
| Message-ID: | CAD43U4WV2yvdp0132NjhGsrcFQgpyCpbH1-8w6twGMpREv=8Wg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Heikki:
On Thu, Nov 20, 2025 at 8:45 AM Heikki Linnakangas <hlinnaka(at)iki(dot)fi> wrote:
> Here's a small patch to replace the int64 parsing code in pgbench with a
> call to strtoi64(). Makes it a little simpler.
>
> Spotted this while grepping for all the different integer parsing
> functions we have. We could probably consolidate them some more, we
> still have quite a different integer-parsing routines in the backend and
> in the frontend. But this is one small, straightforward step in that
> direction.
>
I wrote a small program to test your patch and found that for strings like "
12 ", it does not handle the trailing spaces and considers the input
invalid. However, the original "strtoint64" function processes the trailing
spaces correctly. Below is the small program I used:
#include <stdio.h>
#include <errno.h>
typedef unsigned long long int64;
#define strtoi64(str, endptr, base) ((int64) strtol(str, endptr, base))
int main(int argc, char **argv)
{
unsigned long long result;
char *end;
char *str = argv[1];
result = strtoi64(str, &end, 10);
if (errno != 0)
{
printf("%s\n", strerror(errno));
return 1;
}
if (end == str || *end != '\0')
{
printf("invalid input syntax for type bigint: \"%s\"\n", str);
return 1;
}
return 0;
}
When running ./test " 12 ", the output is:
invalid input syntax for type bigint: " 12 "
$ uname -a
Linux dev 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64
x86_64 x86_64 GNU/Linux
Regards,
Shi Yuefei
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Peter Smith | 2025-11-20 00:59:48 | Re: CREATE/ALTER PUBLICATION improvements for syntax synopsis |
| Previous Message | Corey Huinker | 2025-11-20 00:54:06 | Re: vacuumdb: add --dry-run |