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;
- 什么是
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
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