Thread: [GENERAL] INSERT INTO: string with apostrophe
The syntax for inserting data into a table uses single quotes to identify strings. When I have a string such as O'Brien do I double the single quotes within the string (i.e., 'O''Brien') or is there another way to include such strings? Rich
On Thu, 29 Jun 2017, Cachique wrote: > That is correct. You can double the single quotes. Another way is to use > the E'...' syntax (i.e., E'O\'Brien'). Or you can use the quote_* > functions ( > https://www.postgresql.org/docs/current/static/functions-string.html) Walter, Thanks for confirming. Regards, Rich
On Thu, 29 Jun 2017, Cachique wrote:That is correct. You can double the single quotes. Another way is to use
the E'...' syntax (i.e., E'O\'Brien'). Or you can use the quote_*
functions (
https://www.postgresql.org/docs/current/static/functions-str ing.html)
Walter,
Thanks for confirming.
I don't know how you'd use the quote_literal with a literal input.
PostgreSQL also offers a feature called dollar-quoting. If you place two dollar signs surrounding an optional string before and after the text.
i.e., $txt$I've got an unescaped quote in me$txt$
These can be nested, and are particularly useful when writing function bodies.
These and more syntax rules can be found here: https://www.postgresql.org/docs/9.6/static/sql-syntax.html In this case section "4.1.2 Constants"
David J.