Re: [GENERAL] Using the dollar sign as a prefix for named parameter of prepared statement. - Mailing list pgsql-general

From Tom Lane
Subject Re: [GENERAL] Using the dollar sign as a prefix for named parameter of prepared statement.
Date
Msg-id 19398.1503846782@sss.pgh.pa.us
Whole thread Raw
In response to [GENERAL] Using the dollar sign as a prefix for named parameter of prepared statement.  (Dmitry Igrishin <dmitigr@gmail.com>)
Responses Re: [GENERAL] Using the dollar sign as a prefix for named parameterof prepared statement.  (Dmitry Igrishin <dmitigr@gmail.com>)
List pgsql-general
Dmitry Igrishin <dmitigr@gmail.com> writes:
> I'm working on finishing beta release of my C++ API for PostgreSQL. The
> library
> have simple SQL parser (preprocessor) to support the queries like that:

>   SELECT :"column", $tag$constant string$tag$
>     FROM :tables
>     WHERE name LIKE :'name' AND
>           sex = $1 AND
>           age > $age

>   where:
>     :"column" is a variable which will be quoted as identifier (like in
> psql),
>     :tables is a variable which will be not be quoted at all (like in psql),
>     :'name' is a variable which will be quoted as literal (like in psql),
>     $1 is a positional parameter,
>     $age is a named parameter

> Is there are any contraindications/caveats/gotchas on using the dollar sign
> as a prefix for the named parameters?

How are you going to distinguish named parameters from dollar-quote tags?
For instance, this is legal:

regression=# select $foobar$stuff$foobar$;
 ?column?
----------
 stuff
(1 row)

I think you're going to end up with weird corner case behaviors if
you try to squeeze still another meaning into "$letters..."

            regards, tom lane


pgsql-general by date:

Previous
From: Dmitry Igrishin
Date:
Subject: [GENERAL] Using the dollar sign as a prefix for named parameter of prepared statement.
Next
From: Dmitry Igrishin
Date:
Subject: Re: [GENERAL] Using the dollar sign as a prefix for named parameterof prepared statement.