In the current manual, Table 9.10
<https://www.postgresql.org/docs/13/functions-string.html#FUNCTIONS-STRING-OTHER>
has this to say about quote_ident():

> Returns the given string suitably quoted to be used as an identifier in
an SQL statement string. Quotes are added only if necessary (i.e., if the
string contains non-identifier characters or would be case-folded).
Embedded quotes are properly doubled. See also Example 42.1
<https://www.postgresql.org/docs/13/plpgsql-statements.html#PLPGSQL-QUOTE-LITERAL-EXAMPLE>
.

No mention of SQL key words which are also double-quoted. There was a
related question on stackoverflow today:

https://stackoverflow.com/questions/66662580/quote-ident-does-not-add-quotes-to-column-name-first

I suggest to at least mention key words:

* Returns the given string suitably quoted to be used as an identifier in
an SQL statement string. Quotes are added only if necessary (i.e., if the
string contains non-identifier characters, would be case-folded, or is a
reserved key word). *Embedded quotes are properly doubled. See also
Example 42.1
<https://www.postgresql.org/docs/13/plpgsql-statements.html#PLPGSQL-QUOTE-LITERAL-EXAMPLE>
.

To be precise: key words marked *"reserved"* or *"(cannot be function or
type)"* in the column "PostgreSQL" of the *SQL Key Words*
<https://www.postgresql.org/docs/current/sql-keywords-appendix.html#KEYWORDS-TABLE>
table are quoted. And if the GUC quote_all_identifiers
<https://www.postgresql.org/docs/current/runtime-config-compatible.html#GUC-QUOTE-ALL-IDENTIFIERS>
is set, then all strings are quoted. If that's not too much information, we
might make it:

*Returns the given string suitably quoted to be used as an identifier in an
SQL statement string. Quotes are added only if necessary: if the string
contains non-identifier characters, would be case-folded, or is a reserved
word (marked "reserved" or "(cannot be function or type)" in Table C.1
<https://www.postgresql.org/docs/current/sql-keywords-appendix.html#KEYWORDS-TABLE>).
Embedded quotes are properly doubled. See also Example 42.1
<https://www.postgresql.org/docs/13/plpgsql-statements.html#PLPGSQL-QUOTE-LITERAL-EXAMPLE>
and quote_all_identifiers
<https://www.postgresql.org/docs/current/runtime-config-compatible.html#GUC-QUOTE-ALL-IDENTIFIERS>.*

Regards
Erwin

Reply via email to