Help Center/ GaussDB/ Centralized_8.x/ SQL Reference/ Appendix/ Dollar-Quoted String Constants
Updated on 2024-06-03 GMT+08:00

Dollar-Quoted String Constants

If a string sequence contains a single quotation mark ('), double the single quotation mark (') to two single quotation marks (''). Otherwise, the SQL statement may fail to be executed.

If a string contains many single quotation marks (') or backslashes (\), the string may be difficult to understand and error-prone because all the single quotation marks (') are doubled.

To make the query more readable in such situations, dollar quoting is provided to write string constants. A dollar-quoted string constant consists of a dollar sign ($), a "tag" of zero or more characters, another dollar sign, an arbitrary sequence of characters that make up the string content, a dollar sign, another tag the same as the previous one, and a dollar sign.

gaussdb=# SELECT $$it's an example$$;
    ?column?     
-----------------
 it's an example
(1 row)