PostgreSQL Tcl Interface Documentation | ||||
---|---|---|---|---|
Prev | Fast Backward | Fast Forward | Next |
pg_quote
quotes a string and escapes single quotes and backslashes within the string, making it safe for inclusion into SQL statements.
If a connection
is provided, the connection is used to customize the quoting process for the database referenced by the connection.
If the [-null] option is provided, then if the text matches the null string (either the empty string, or the null string specified in the connection
) then the SQL keyword NULL is returned, rather than a quoted string.
If you're doing something like
pg_exec $conn "insert into foo values ('$name');"
and name
contains text includeing an unescaped single quote, such as Bob's House, the insert will fail. Passing value strings through pg_quote
make sure they can be used as values and stuff in PostgreSQL.
pg_exec $conn "insert into foo values ([pg_quote $name]);"
...will make sure that any special characters that occur in name, such as single quote or backslash, will be properly quoted.