> For the complete documentation index, see [llms.txt](https://ploegert.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ploegert.gitbook.io/til/programmy/linux/is-app-installed/string-operations/escaping-string-literals-with-dollar-quoting.md).

# Escaping String Literals With Dollar Quoting

String literals in PostgreSQL are defined by surrounding the content with the `'` character. For string literals that contain the `'` character, you may have seen it escaped with a preceding `'`.

```sql
> select 'Isn''t this nice?';
     ?column?
------------------
 Isn't this nice?
```

This is easy enough to do, but can be error prone and doesn't work well if SQL is being programmatically generated. A great workaround is to escape string literals using what is called dollar quoting.

```sql
> select $$Isn't this even nicer?$$;
        ?column?
------------------------
 Isn't this even nicer?
```

Just wrap both ends in `$$` instead of `'`.

[source](https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html)
