Function quote_ident

Source
pub fn quote_ident(s: &str, writer: &mut impl Write)
Expand description

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.

Refer to https://github.com/postgres/postgres/blob/90189eefc1e11822794e3386d9bafafd3ba3a6e8/src/backend/utils/adt/ruleutils.c#L11506

ยงExample

query T
select quote_ident('foo bar')
----
"foo bar"

query T
select quote_ident('FooBar')
----
"FooBar"

query T
select quote_ident('foo_bar')
----
foo_bar

query T
select quote_ident('foo"bar')
----
"foo""bar"

# FIXME: quote SQL keywords is not supported yet
query T
select quote_ident('select')
----
select