Using the dollar sign as a prefix for named parameter of prepared statement.

From: Dmitry Igrishin <dmitigr(at)gmail(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Using the dollar sign as a prefix for named parameter of prepared statement.
Date: 2017-08-27 09:15:55
Message-ID: CAAfz9KOmQK1FKJXCao2kJu6ZuhhnQzmkz9930MHe1tvjHKOy4g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

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?

According to
https://www.postgresql.org/docs/10/static/sql-syntax-lexical.html

a) "SQL identifiers and key words must begin with a letter ..."
b) "The tag, if any, of a dollar-quoted string follows the same rules as an
unquoted identifier ... "
c) "A dollar sign ($) followed by digits is used to represent a positional
parameter in the body of a function definition or a prepared statement. In
other contexts the dollar sign can be part of an identifier or a
dollar-quoted string constant."

I don't see any problems with such a choise. Am I missing something?

Thanks!

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2017-08-27 15:13:02 Re: Using the dollar sign as a prefix for named parameter of prepared statement.
Previous Message Igor Korot 2017-08-27 00:41:03 Problem during debugging