What is the $$ function in posntegresql functions?

Asked

Viewed 58 times

5

Hello, I’m a beginner in postegrsql and I have the following question:
When we create functions in postgresql the following logic is usually used

CREATE FUNCTION func() RETURNS ret AS $$ 
BEGIN
...
END;
$$ LANGUAGE plpgsql;

From what I read the $$ are body delimiters of the function, I wonder if what this between the two $ has some extra function. I’ve seen functions where it’s only used $$, where it is used $BODY$ or also $function name$. Does this interfere with the function or schema? Is there any market standard?

  • 1

    The use of $$ or $something$ is just a facilitator to delimit the body of the function. In the older versions the body of the function between apostrophes was used (') but this created a problem if the in the body of the function you needed to use the apostrophe being necessary to duplicate or quadruple to function properly. Ah! , and the name is Postgresql.

1 answer

3


In Postgresql, dollar signs are used to replace single quotes in user-defined functions and stored procedures. In some cases it is difficult to understand when the string has too many single quotes or backslashes, because they need to be duplicated. So, to make the query more readable, it provides this use of $$ to write the constants. The function body should also be placed between single quotes, so it can be replaced by $$.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.