CREATE FUNCTION one() RETURNS integer AS $$
SELECT 1 AS result;
$$ LANGUAGE SQL;
为什么我不能这样写:
CREATE FUNCTION one() RETURNS integer
SELECT 1 AS result;
- 什么是
AS $$
? - 什么是
$$ LANGUAGE SQL
? - 什么是
$$
?
在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