sql 函数中的 `AS $$` 是什么?

What is `AS $$` in sql functions?

CREATE FUNCTION one() RETURNS integer AS $$
    SELECT 1 AS result;
$$ LANGUAGE SQL;

为什么我不能这样写:

CREATE FUNCTION one() RETURNS integer
    SELECT 1 AS result;

在 PostgreSQL 中,这是一个称为美元引用的功能,它允许您在不转义单引号的情况下包含文本正文

用作

CREATE OR REPLACE FUNCTION hello_world(param_your_name text)
RETURNS text AS
$$
SELECT 'Hello world. My name is ' || param_your_name || '.';
$$
language sql STRICT;

更易读
CREATE OR REPLACE FUNCTION hello_world(param_your_name text)
RETURNS text AS
'
SELECT ''Hello world. My name is '' || param_your_name || ''.'';
'
language sql STRICT;

在此处阅读更多信息 - https://www.postgresonline.com/journal/archives/376-Dollar-quoting-for-escaping-single-quotes.html