pg_escape_identifier — Escape a string for use as an SQL identifier (object name)


pg_escape_identifier conn string


pg_escape_identifier returns its string argument safely escaped and quoted for use as an SQL identifier (a table name, column name, etc.). Use this command when you have an unknown or variable string representing an SQL identifier that you are using in an SQL statement, or have an SQL identifier name in a Tcl variable that might contain double quotes or spaces.



Handle of the connection that the identifier will be used with. (Note: This argument is not used by pgintcl.)


The string to escape and quote.

Return Value

The string argument, suitable for use as an identifier, including surrounding double quotes.


Use of double quotes around an identifier makes PostgreSQL treat that identifier as case sensitive.


See also pg_quote, pg_escape_string, and pg_escape_literal.

This command was added in pgtclng-2.1.0 and in pgintcl-3.5.0.

The conn argument is used to get character set encoding information, which is used to make sure that multi-byte characters do not confuse the escaping process.


Unlike libpq-based interface implementations, Pgintcl does not have the ability to use character set encoding information, and so it does not use the conn parameter at all.

This command uses or emulates the PostgreSQL libpq function PQescapeLiteral, which was added in PostgreSQL-9.0.0.


set sql "SELECT * FROM [pg_escape_identifier $conn $tablename] ORDER BY 1" Logo

This version of the manual was produced for the Pgtcl-ng Sourceforge project web service site, which requires the logo on each page.

To download a logo-free copy of the manual, see the Pgtcl-ng project downloads area.