SQL comments in MaxCompute improve code readability by annotating logic inline. This topic describes how to write single-line and multi-line comments in MaxCompute SQL scripts.
Limitations
-
Multi-line comments are not available on the DataWorks data development interface.
-
To use SQL comments in the MaxCompute local client (odpscmd), the odpscmd version must be 0.49.0 or later.
-
In the MaxCompute client (odpscmd) and Cloud Shell (odpscmd), a semicolon (
;) is required to terminate a single-line comment. Semicolons are not supported in multi-line comments.
Syntax
Single-line comments
Start a single-line comment with --. Everything from -- to the end of the line is treated as a comment.
-- Comment content
Place the comment on its own line above the code, or at the end of a line of code.
In the MaxCompute console SQL analysis interface or the DataWorks data development interface, use Ctrl+/ to comment out a line of code.
Multi-line comments
Use /* to open and */ to close a multi-line comment, allowing you to comment out a block of content at once.
/*
Comment
content
*/
MaxCompute also supports /*+...*/ as Hint syntax — for example, MAPJOIN hints and SKEWJOIN HINT. Hints take precedence over multi-line comments. To avoid ambiguity, use /** instead of /* as the opening symbol for multi-line comments.
Examples
The following examples use my_table as an existing table.
Single-line comment
The following example shows a single-line comment placed above a statement and at the end of a line:
-- Single-line comment
DESC my_table; -- Single-line comment
Multi-line comment
The following example shows a multi-line comment embedded in a SELECT statement:
SELECT /* Valid
multi-line
comment
*/ * FROM my_table;
Common mistake: /*+ misinterpreted as a Hint
Opening a multi-line comment with /*+ causes MaxCompute to interpret it as the start of a Hint rather than a comment:
SELECT /*+ Invalid
multi-line
comment
*/ * FROM my_table;
To avoid this, use /** as the opening symbol for multi-line comments.