Underscore in positional parameters?

Поиск
Список
Период
Сортировка
От Erik Wienhold
Тема Underscore in positional parameters?
Дата
Msg-id 5d216d1c-91f6-4cbe-95e2-b4cbd930520c@ewie.name
обсуждение исходный текст
Ответы Re: Underscore in positional parameters?
Список 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

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Andy Fan
Дата:
Сообщение: Re: UniqueKey v2
Следующее
От: Andy Fan
Дата:
Сообщение: Re: UniqueKey v2