There are two methods of commenting in PL/pgSQL, both similar to the comment structure of other programming
languages. The two methods are single-line comments, and block comments (multiple line comments).
The first method of commenting is single line commenting. Single line comments begin with two dashes (- -)
and have no end-character. The parser interprets all characters on the same line after the two dashes as part of the
comment. Example 11-6 demonstrates the use of single line comments.
Example 11-6. Using single-line comments
-- This will be interpreted as a single-line comment.
The second type of comment is the multiline or
comment, which should be familiar to
most anyone who has worked with programming languages before. Block comments begin with the forward slash and asterisk
characters (/*) and end with the asterisk and forward slash characters (*/).
Block comments can span multiple lines, and any text between the opening /* and closing
*/ is considered a comment. Example 11-7 shows the correct usage
of a block comment.
Example 11-7. Using block comments
* This is a
Note: While single-line comments can be nested within block comments, block comments cannot be nested within other block comments.
In any programming language, it is helpful to write useful comments. A comment is considered useful if it can
express to the user why a certain section of code was designed a certain way, or why syntax was used in an abnormal or
creative manner. Comments that restate what is happening programmatically can be helpful at times, but you must remain
aware of what is happening in your program and be sure to express
certain things are being done
(instead of just
In our PL/pgSQL code examples we will use comments to explain how and why we do certain things within a particular
section of code. This is to help you, as a new PL/pgSQL user, learn more about the language and its uses.