PostgreSQL Tcl Interface Documentation
Prev | Fast Backward |  | Fast Forward | Next

# pg_quote

## Name

pg_quote -- escapes a string for inclusion into SQL statements

## Synopsis

    pg_quote string

## Description

`pg_quote` quotes a string and escapes single quotes and backslashes within the string, making it safe for inclusion into SQL statements.

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.

## Arguments

string

  The string to be escaped.

## Return Value

Returns the string, escaped for inclusion into SQL queries. Note that it adds a set of single quotes around the outside of the string as well.

Prev | Home | Next
pg_null_value_string | Up | pg_escape_string