“ $$”是什么?在Postgresql函数中意味着什么? [英] What does the "$$" mean in Postgresql function?

查看:2279
本文介绍了“ $$”是什么?在Postgresql函数中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CREATE OR REPLACE FUNCTION increment(i integer) RETURNS integer AS $$
        BEGIN
                RETURN i + 1;
        END;
$$ LANGUAGE plpgsql;

以上代码取自Postgresql网站。但是我不明白为什么使用 $$ 。我在网上的多个示例中都看到了它,但没有一个可以真正解释为什么要使用它。还是有必要?

The above code is taken from the Postgresql website. However I do not understand why $$ is used. I have seen it at multiple examples online and none of them actually explains why that is used. Or is it even necessary?

推荐答案

从手册中获取 create函数语句:


定义

定义函数的字符串常量;含义取决于语言。它可以是内部函数名称,目标文件的路径,SQL命令或过程语言中的文本。

A string constant defining the function; the meaning depends on the language. It can be an internal function name, the path to an object file, an SQL command, or text in a procedural language.

使用美元引号 (请参阅第4.1.2.4节)来编写函数定义字符串,而不是普通的单引号语法。没有美元引号,函数定义中的任何单引号或反斜杠都必须通过加倍来转义。

It is often helpful to use dollar quoting (see Section 4.1.2.4) to write the function definition string, rather than the normal single quote syntax. Without dollar quoting, any single quotes or backslashes in the function definition must be escaped by doubling them.

第4.1.2.4节解释了美元报价


用美元报价的字符串常量包含一个美元符号($),一个零个或多个字符的可选标记,另一个美元符号,组成字符串内容的任意字符序列,美元符号,以美元开头的相同标签和美元符号。例如,以下两种方法可以使用美元引号

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. For example, here are two different ways to specify the string "Dianne's horse" using dollar quoting

这篇关于“ $$”是什么?在Postgresql函数中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆