Postgresql函数中的“$$”是什么意思?

What does the "$$" mean in Postgresql function?

CREATE OR REPLACE FUNCTION increment(i integer) RETURNS integer AS $$
        BEGIN
                RETURN i + 1;
        END;
$$ LANGUAGE plpgsql;

以上代码摘自Postgresql网站。但是我不明白为什么使用 $$ 。我在多个在线示例中看到过它,其中 none 实际上解释了为什么使用它。甚至有必要吗?

From the manual 对于 create function 语句:

definition

A string constant defining the function; the meaning depends on the language. It can be an internal function name, the path to an object file, an SQL command, or text in a procedural language.

It is often helpful to use dollar quoting (see Section 4.1.2.4) to write the function definition string, rather than the normal single quote syntax. Without dollar quoting, any single quotes or backslashes in the function definition must be escaped by doubling them.

Section 4.1.2.4 explains the dollar quoting:

A dollar-quoted string constant consists of a dollar sign ($), an optional "tag" of zero or more characters, another dollar sign, an arbitrary sequence of characters that makes up the string content, a dollar sign, the same tag that began this dollar quote, and a dollar sign. For example, here are two different ways to specify the string "Dianne's horse" using dollar quoting