views:

51

answers:

1

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.

+5  A: 

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.

Marcelo Cantos
Allowing different strings enables simpler nesting.
Stephen Denne