在psql
中,以\
开头的特殊命令的注释字符是什么?
以下似乎有效:
SELECT * FROM my_table -- this is my comment
但这不起作用:
\dt jvcurve_thin.jvcurve_results -- my comment #2
\dt:忽略额外的参数“--”
在psql
中,以\
开头的特殊命令的注释字符是什么?
以下似乎有效:
SELECT * FROM my_table -- this is my comment
但这不起作用:
\dt jvcurve_thin.jvcurve_results -- my comment #2
\dt:忽略额外的参数“--”
SELECT 23 AS test -- this is just a test
块级样式:block
/* The following is a very
* non-trivial SQL code */
SELECT 42 AS result
--
开头。/* comment */
。 - mu is too shortpsql
中添加注释(元命令)的跟进问题(例如,\l
用于列出数据库)。在这个时间点上,只有cjerdonek的答案回答了这些跟进问题。 - David J.看起来 psql
不支持在其特定于 psql
的“斜线命令”中使用传统的行末注释 --
。-- 在PostgreSQL psql文档中,这些被称为元命令。
然而,如果您可以接受在执行时显示行末注释,则使用\echo
似乎是一个有效的解决方法。例如:
\dt jvcurve_thin.jvcurve_results \echo my comment #2
“双斜杠”分隔符元命令似乎是另一种可能性(并且没有回显的副作用)。 用它开启一个新命令,然后立即开始一个--
注释:
\dt jvcurve_thin.jvcurve_results \\ -- my comment #2
\dt jvcurve_thin.jvcurve_results \! # my comment #2
psql
命令,例如 \d table1 \\ \d table2
,并且当所谓的注释包含 psql
命令时会表现出行为。请参见此处选项 -c
的说明(http://www.postgresql.org/docs/9.1/static/app-psql.html)。 - valid--
,就像\\ --
我的评论一样,怎么样? - cjerdonek来自官方文档:PostgreSQL注释。
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.
自黑暗时代(版本7.0)以来,它一直以相同的方式得到支持。
在PostgreSQL pgAdmin4中,最好选择并按Ctrl+Shift+/来注释多行代码。
psql
不支持在其斜线命令后添加尾随行注释,只能将注释放在前一行。 - Craig Ringer