$BODY$ on postgresql trigger function 是干什么用的?

On what $BODY$ on postgresql trigger function is used for?

我找到了一些 postgresql 触发器教程。有这个示例函数:

CREATE OR REPLACE FUNCTION add_log_trigg_function() RETURNS trigger AS
$BODY$
DECLARE
    account_type varchar;
BEGIN
    IF (TG_TABLE_NAME = 'account_current') THEN
        account_type := 'Current';
        RAISE NOTICE 'TRIGER called on %', TG_TABLE_NAME;

    ELSIF (TG_TABLE_NAME = 'account_savings') THEN
        account_type := 'Savings';
        RAISE NOTICE 'TRIGER called on %', TG_TABLE_NAME;

    END IF;

    RETURN null;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION add_log_trigg_function()
  OWNER TO postgres;

我知道 $BODY$ 启动了 body 功能。但为什么要命名呢?这个名字BODY在其他地方可以或常用吗?除了LANGUAGECOSTALTER FUNCTION命令外,还有哪些命令通常留在$BODY$之外?

https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-DOLLAR-QUOTING

A dollar-quoted string constant consists of a dollar sign ($), an optional “tag” of zero or more characters, another dollar sign, an arbitrary sequence of characters that makes up the string content, a dollar sign, the same tag that began this dollar quote, and a dollar sign.

简而言之 - 你可以放置任何标签 - 而不仅仅是 BODY 触发器或 function 用于 \sf 作为 psql 通常格式化它。样本:

t=# do
$anything$
begin
 raise info '%', 'any tag would work';
end;
$anything$
;
INFO:  any tag would work
DO

也回答任何它应该被命名的 - 它应该 not.jut $$$BODY$ 一样好,但是当你需要使用引号时 "naming" 非常有用里面引用。就像在我上面的示例中一样,我使用 raise 的单引号引号,并且我不需要将单引号加倍或将它们转义以在正文中使用,因为我已经使用了美元符号引号。可能更清晰的样本是:

t=# do
$anything$
begin
 raise info $$%$$, $someothertag$any tag would work$someothertag$;
end;
$anything$
;
INFO:  any tag would work
DO