chickadee » postgresql » quote-identifier

quote-identifier CONNECTION STRINGprocedure

Escapes special characters in STRING which are otherwise interpreted by the SQL parser, obeying the CONNECTION's encoding settings and escaping settings, using the escaping syntax for identifier context. Identifiers are table names, aliases etc. Surrounding double quotes will be added.

This procedure corresponds to PQescapeIdentifier, but the name was changed to reflect the fact that it performs escaping and adds quotation marks around the string.

NOTE: This procedure is only available when the egg is built against the libpq from PostgreSQL 9.0 or later. If you are using an older version, this will raise a (exn postgresql unsupported-version) error with an upgrade message.

Example:

;; Spaces are normally not allowed in table names, but when you
;; quote them, they are allowed
(quote-identifier conn "a table with spaces") => "\"a table with spaces\""

;; Can't use a column or table called order because it is a
;; reserved word. However, escaping it makes it usable.
(quote-identifier conn "order") => "\"order\""

;; Table names are case-insensitive and always implicitly downcased.
;; If you need to access a table with a capital in its name,
;; quoting the table also helps:
(quote-identifier conn "Foo") => "\"Foo\""