Question

I'm not even sure what this is called?

But I'm trying to learn what the difference is between writing a function like this is in plpgsql:

CREATE OR REPLACE FUNCTION foo() RETURNS TRIGGER AS $$
    ....
$$ LANGUAGE plpgsql;

vs

CREATE OR REPLACE FUNCTION foo() RETURNS TRIGGER AS $foo$
    ....
$foo$ LANGUAGE plpgsql;

is there a difference when using $$ vs $foo$? why would someone choose one over another? perhaps I've just missed some documentation explaining the difference. If someone could enlighten me, I'd really appreciate it.

Was it helpful?

Solution

Whatever you type between the $ signs after the AS becomes the delimiter tag. You could write:

CREATE OR REPLACE FUNCTION foo() RETURNS TRIGGER AS $!!unicorns!!$
    ....
$!!unicorns!!$ LANGUAGE plpgsql;

The $...$ notation denotes a dollar-quoted string constant in PostgreSQL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top