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