Hi Heikki:

On Thu, Nov 20, 2025 at 8:45 AM Heikki Linnakangas <[email protected]> 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

Reply via email to