SQL comments let you annotate a statement. They are discarded during lexical analysis and have no effect on results, query planning, or query caching: a statement behaves exactly as if its comments were not there.
The Relational Layer supports two comment styles:
Line comments start with -- and continue to the end of the line.
Block comments are delimited by /* and */, may span multiple lines, and may be nested.
-- Select the premium products.SELECTnameFROMproductsWHEREprice>100ORDERBYname;SELECTname/* only the name */FROMproductsWHEREprice>100/* this predicate spans multiple lines */ORDERBYname;
Following the ANSI SQL and PostgreSQL convention, -- begins a comment even when it is not followed by whitespace, so SELECT1--comment is equivalent to SELECT1.
A line comment ends at the first line break, which may be a line feed, a carriage return, or a carriage return followed by a line feed, or at the end of the statement if no line break follows.
Block comments nest: a /* inside a block comment starts an inner comment that must be closed before the enclosing one. A region containing comments can therefore be commented out as a whole.
SELECTname/* outer /* inner */ still a comment */FROMproducts;
A block comment that is never closed is a syntax error, rather than a comment that runs to the end of the statement.
Comments are only recognized outside of string literals and quoted identifiers. The sequences -- and /* inside a quoted string are ordinary data, so the literal 'a--b' retains its value verbatim, and a quoted identifier such as "a--b" keeps its exact spelling.
Note
The Relational Layer does not support # line comments or /*!...*/ executable comments, which some SQL dialects provide. Outside of a string literal, # is a syntax error, and a /*!...*/ sequence is treated as an ordinary block comment (its contents are ignored rather than executed).
Because comments never reach the query engine, they cannot be used to pass hints to the planner.
CommentsΒΆ
SQL comments let you annotate a statement. They are discarded during lexical analysis and have no effect on results, query planning, or query caching: a statement behaves exactly as if its comments were not there.
The Relational Layer supports two comment styles:
Line comments start with
--and continue to the end of the line.Block comments are delimited by
/*and*/, may span multiple lines, and may be nested.Following the ANSI SQL and PostgreSQL convention,
--begins a comment even when it is not followed by whitespace, soSELECT 1--commentis equivalent toSELECT 1.A line comment ends at the first line break, which may be a line feed, a carriage return, or a carriage return followed by a line feed, or at the end of the statement if no line break follows.
Block comments nest: a
/*inside a block comment starts an inner comment that must be closed before the enclosing one. A region containing comments can therefore be commented out as a whole.A block comment that is never closed is a syntax error, rather than a comment that runs to the end of the statement.
Comments are only recognized outside of string literals and quoted identifiers. The sequences
--and/*inside a quoted string are ordinary data, so the literal'a -- b'retains its value verbatim, and a quoted identifier such as"a--b"keeps its exact spelling.Note
The Relational Layer does not support
#line comments or/*! ... */executable comments, which some SQL dialects provide. Outside of a string literal,#is a syntax error, and a/*! ... */sequence is treated as an ordinary block comment (its contents are ignored rather than executed).Because comments never reach the query engine, they cannot be used to pass hints to the planner.