What does "$$" mean in postgresql function?

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

      

The above code is from the postgresql website. However, I don't understand why $$ is used. I've seen this in several examples online and none of them explain why this is being used. Or is it even necessary?

+3


source to share


1 answer


From the operator's manualcreate function

:

definition

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

It is often useful to use dollar quotes (see section 4.1.2.4) to write the function definition line rather than the usual syntax. Without a dollar quote, any single quotes or backslashes in a function definition must be escaped by doubling them.



Section 4.1.2.4 explains the dollar quote :

A dollar-enclosed string constant consists of a dollar sign ($), an optional "tag" of zero or more characters, another dollar sign, an arbitrary sequence of characters that make up the contents of the string, a dollar sign, the same tag that started that dollar quote, and dollar sign. For example, here are two different ways to specify the string "Dianne horse" using dollar quotation

+5


source







All Articles