Underscore in positional parameters? - Mailing list pgsql-hackers

From Erik Wienhold
Subject Underscore in positional parameters?
Date
Msg-id 5d216d1c-91f6-4cbe-95e2-b4cbd930520c@ewie.name
Whole thread Raw
Responses Re: Underscore in positional parameters?
List pgsql-hackers
I noticed that we (kind of) accept underscores in positional parameters.
For example, this works:

    => PREPARE p1 AS SELECT $1_2;
    PREPARE
    => EXECUTE p1 (123);
     ?column?
    ----------
     123
    (1 row)

Parameter $1_2 is taken as $1 because in rule {param} in scan.l we get
the parameter number with atol which stops at the underscore.  That's a
regression in faff8f8e47f.  Before that commit, $1_2 resulted in
"ERROR: trailing junk after parameter".

I can't tell which fix is the way to go: (1) accept underscores without
using atol, or (2) just forbid underscores.  Any ideas?

atol can be replaced with pg_strtoint32_safe to handle the underscores.
This also avoids atol's undefined behavior on overflows.  AFAICT,
positional parameters are not part of the SQL standard, so nothing
prevents us from accepting underscores here as well.  The attached patch
does that and also adds a test case.

But reverting {param} to its old form to forbid underscores also makes
sense.  That is:

    param            \${decdigit}+
    param_junk        \${decdigit}+{ident_start}

It seems very unlikely that anybody uses that many parameters and still
cares about readability to use underscores.  But maybe users simply
expect that underscores are valid here as well.

-- 
Erik

Attachment

pgsql-hackers by date:

Previous
From: Andy Fan
Date:
Subject: Re: UniqueKey v2
Next
From: Andy Fan
Date:
Subject: Re: UniqueKey v2