I have seen the double dollar sign ($$) being used often in FUNCTION declarations and while doing declare statements. I acknowledge that it is probably some syntax related feature, but I am not too clear how/why to use it and when.
Code examples of usage below:
CREATE OR REPLACE FUNCTION BuildFunction(IN prefix TEXT, IN func_id INTEGER) RETURNS BOOLEAN AS $$
BEGIN
...
END; $$
Point of confusion, how do you return a boolean as a $$, is it some special type or something?
DO $$
DECLARE
a integer := 10;
b integer := 20;
c integer;
BEGIN
c := a + b;
RAISE NOTICE'Value of c: %', c;
END $$;
This code snippet is from How do you use variables in a simple PostgreSQL script?
From the fine manual:
The dollar quoting is a PostgreSQL-specific way of quoting strings that will contain a lot of internal single quotes without forcing you to escape quotes and make an unreadable mess. So these are equivalent string literals:
Dollar-quoting isn't specific to functions, you can use it for any string literals, but it is most commonly seen in function definitions as in your two examples.