PG_ESCAPE_STRING(n)
π PG_ESCAPE_STRING() π
okay bestie, welcome to the PostgreSQL Tcl Interface Documentation page for pg_escape_string β she's here to keep your SQL from going feral. π¦
πΈ NAME πΈ
pg_escape_string β escapes a string for inclusion into SQL statements. It's literally the same as pg_quote; it was added for consistency. no cap β¨
β¨ SYNOPSIS β¨
pg_escape_string string
π¦ DESCRIPTION π¦
pg_escape_string quotes a string and escapes single quotes and backslashes within the string, making it safe for inclusion into SQL statements. it's giving "safety but make it cute" π
If you're doing something like:
pg_exec $conn "insert into foo values ('$name');"
and name contains text including an unescaped single quote β like Bob's House β then at best the insert will fail, and at worst your software will be exploited via an SQL injection attack. π (not the vibe, bestie.)
Passing value strings through pg_escape_string will properly quote them for insertion into SQL commands. Like:
pg_exec $conn "insert into foo values ([pg_escape_string $name]);"
...will make sure that any special characters that occur in name, such as a single quote or a backslash, will be properly quoted. periodt. π₯
β οΈ real talk: that SQL injection scenario is why escaping matters. escape your strings before they end up in the group chat. π
π ARGUMENTS π
stringβ the string to be escaped, bestie. π
π RETURN VALUE π
Returns the string, escaped for inclusion into SQL queries. Note that it also adds a set of single quotes around the outside of the string as well β so yes, she's doing the absolute most, and that's on purpose. π
π SEE ALSO π
In most cases, with recent versions of SQL, it is better to use the native parameter insertion capabilities of the SQL server and protocol. π«Ά
If you are using a version of PostgreSQL more recent than 7.4, consider the optional parameter arguments to pg_exec and pg_sendquery, and the paramarray option to pg_exec, pg_sendquery, and pg_select. iykyk π
xoxo bestie π β source/version: PostgreSQL Tcl Interface Documentation, dated 17 September 2020. bye π«Ά
π¦ where this page comes from
- alpine 3.22: pgtcl-doc 3.1.0-r0 Β· BSD-3-Clause
- alpine 3.23: pgtcl-doc 3.1.1-r0 Β· BSD-3-Clause
- alpine 3.24: pgtcl-doc 3.1.1-r0 Β· BSD-3-Clause
- nixpkgs unstable: pgtcl 3.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms