All Products
Search
Document Center

MaxCompute:SQL comments

Last Updated:Nov 19, 2024

To improve code readability, you can write comments in your MaxCompute SQL scripts. This topic describes how to use single-line and multi-line comments in MaxCompute SQL scripts.

Limits

  • The multi-line comment feature is not available on the DataWorks data development interface.

  • To use SQL comments in the local client (odpscmd) of the MaxCompute, the odpscmd version must be 0.49.0 or later.

  • When using single-line comments in the MaxCompute client (odpscmd) or Cloud Shell (odpscmd), a semicolon (;) is required to terminate the comment. Semicolons are not supported in multi-line comments.

Syntax format

Single-line comments

Start single-line comments with --. The syntax is as follows:

-- Comment content

Any text from -- to the end of the line is treated as a comment. You can place the comments on a separate line above the code or at the end of a line of code.

Note

In the SQL analysis interface of the MaxCompute console or the DataWorks data development interface, you can use the Ctrl+/ shortcut to comment out a line of code.

Multi-line comments

For multi-line comments, use /* to begin and */ to end, allowing you to comment out blocks of content at once. The syntax is as follows:

/* 
Comment
content
*/
Important

MaxCompute also supports /*+...*/ as Hint syntax, such as MAPJOIN hints and SKEWJOIN HINT. Hints take precedence over multi-line comments, so ensure the start symbol of the multi-line comment is not mistaken for a Hint start symbol. We recommend that you can use /** as the start symbol for multi-line comments to avoid confusion.

Usage examples

Consider my_table as an existing table. The following codes show the examples of comments:

  • Example 1: A correct single-line comment.

    -- Single-line comment
    DESC my_table; -- Single-line comment
  • Example 2: A correct multi-line comment.

    SELECT /* Valid
    multi-line
    comment
    */ * FROM my_table;
  • Example 3: An incorrect multi-line comment where /*+ is misinterpreted as the beginning of a Hint.

    SELECT /*+ Invalid
    multi-line
    comment
    */ * FROM my_table;