postgres / postgresql / psql 中的注释字符/字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4272251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Comment character/characters in postgres / postgresql / psql?
提问by russian_spy
What's the character for comments in postgres?
postgres中评论的字符是什么?
SELECT * FROM my_table # pound sign produces a syntax error
Thank you cababunga, the following appears to work:
谢谢cababunga,以下似乎有效:
SELECT * FROM my_table -- this is my comment
But this does not work:
但这不起作用:
\dt jvcurve_thin.jvcurve_results -- my comment #2
\dt: extra argument "--" ignored
\dt: 额外的参数“--”被忽略
回答by Tregoreg
According to PostgreSQL documentation, there are both the inline and the block style comments.
根据 PostgreSQL 文档,有内联和块样式注释。
The inlinestyle:
该内嵌样式:
SELECT 23 AS test -- this is just a test
The blockstyle:
该块样式:
/* The following is a very
* non-trivial SQL code */
SELECT 42 AS result
回答by cababunga
In SQL comment starts with --
.
在 SQL 中,注释以--
.
回答by vitaly-t
From the official documentation: PostgreSQL Comments.
来自官方文档:PostgreSQL Comments。
A comment is a sequence of characters beginning with double dashes and extending to the end of the line, e.g.:
-- This is a standard SQL comment
Alternatively, C-style block comments can be used:
/* multiline comment * with nesting: /* nested block comment */ */
where the comment begins with /* and extends to the matching occurrence of */. These block comments nest, as specified in the SQL standard but unlike C, so that one can comment out larger blocks of code that might contain existing block comments.
A comment is removed from the input stream before further syntax analysis and is effectively replaced by whitespace.
注释是一系列以双破折号开头并延伸到行尾的字符,例如:
-- This is a standard SQL comment
或者,可以使用 C 风格的块注释:
/* multiline comment * with nesting: /* nested block comment */ */
其中注释以 /* 开始并扩展到匹配的 */。这些块注释嵌套在 SQL 标准中,但与 C 不同,因此可以注释掉可能包含现有块注释的较大代码块。
在进一步语法分析之前从输入流中删除注释,并有效地替换为空格。
And it has been supported the same way ever since dark ages (version 7.0).
自黑暗时代(7.0 版)以来,它一直以相同的方式得到支持。
回答by cjerdonek
It doesn't look like psql
supports traditional end-of-line --
comments in its psql
-specific "slash commands."
它看起来不像在其特定的“斜杠命令”中psql
支持传统的行尾--
注释psql
。
However, if you're okay with the end-of-line comments being displayed on execution, using \echo
seems to be a valid work-around. For example:
但是,如果您对在执行时显示的行尾注释感到满意,则 using\echo
似乎是一种有效的解决方法。例如:
\dt jvcurve_thin.jvcurve_results \echo my comment #2
The "double slash" separator meta-command looks like another possibility (and without the side effect of echoing). Begin a new command with it and immediately start a --
comment:
“双斜线”分隔符元命令看起来是另一种可能性(并且没有回显的副作用)。用它开始一个新命令并立即开始--
评论:
\dt jvcurve_thin.jvcurve_results \ -- my comment #2
Finally, switching to the shell and adding a shell comment seems like another possibility:
最后,切换到 shell 并添加 shell 注释似乎是另一种可能性:
\dt jvcurve_thin.jvcurve_results \! # my comment #2
回答by Saad
It's Better to select and press Ctrl+Shift+/ to comment multiline in PostgreSQL pgAdmin4
在 PostgreSQL pgAdmin4 中选择并按 Ctrl+Shift+/ 注释多行会更好