PostgreSQL Escape & Unescape

Escape special characters in strings for safe PostgreSQL queries. Prevent SQL injection and syntax errors.

Client-side only — nothing leaves your browser

Result will appear here...

Standard Escaping

Double single quotes to escape them inside string literals.

'John''s data'

E'...' Strings

Use backslash escapes for special characters like newlines.

E'Line1\nLine2'

Dollar Quoting

No escaping needed inside dollar-quoted strings.

$$John's data$$

LIKE Pattern

Escape % and _ for literal matches in LIKE queries.

LIKE '10\%'

Identifier

Wrap reserved words or special names in double quotes.

"user", "order"

Common Examples

OriginalEscaped (Standard)Usage
John'sJohn''sSingle quote in names
It's a "test"It''s a "test"Mixed quotes
C:\path\fileC:\\path\\fileWindows paths
Line1 Line2Line1\nLine2 (E'' string)Multiline text
10%10\%LIKE pattern (literal %)
user_nameuser\_nameLIKE pattern (literal _)
user"user"Reserved word as identifier

Frequently Asked Questions

What is dollar quoting in PostgreSQL?
Dollar quoting ($$...$$) is a PostgreSQL-specific syntax that lets you write strings without escaping. Any text between $$ delimiters is taken literally. You can also use tagged dollar quotes like $tag$...$tag$ to nest dollar-quoted strings.
What is an escape sequence in PostgreSQL?
An escape sequence is a combination of characters that represents a special character inside a string. PostgreSQL supports them in E-strings (E'...'), where backslash sequences like \n (newline), \t (tab), \' (single quote), and \\ (backslash) are interpreted. Standard strings don't process escape sequences — backslashes are treated as literal characters unless standard_conforming_strings is turned off.
When should I use dollar quoting vs standard escaping?
Use dollar quoting when your string contains many single quotes or backslashes (like in function bodies or complex text). Use standard escaping for simple strings. Dollar quoting is cleaner for multi-line strings and code blocks.
How do I escape special characters in a PostgreSQL password?
In connection strings, URL-encode special characters in passwords: @ becomes %40, : becomes %3A, / becomes %2F, and so on. In SQL commands, use standard string escaping (double single quotes) when setting passwords with ALTER USER.
How do I escape special characters in PostgreSQL JSON?
Inside PostgreSQL JSON strings, double quotes must be escaped as \" and backslashes as \\. Use the jsonb_build_object() or to_jsonb() functions to safely build JSON without manual escaping. When querying, the ->> operator returns text with escapes already resolved, while -> returns raw JSON with escapes preserved.
PostgreSQL

Need a PostgreSQL GUI Client?

1bench is a modern database client for PostgreSQL and 20+ other databases. Query, browse, and manage your data visually.

Learn More