PostgreSQL Comments

Comments are used to explain the Query in PostgreSQL to make the code more readable and easier to understand. Comments can also be used to prevent execution of PostgreSQL statements.

There are two types of comments: single-lined and multi-lined.

Single Line Comments :

Single line comments begins with --
Any text between -- the end of the line will be ignored (not executed).
This method of commenting can only span a single line within your PostgreSQL and must be at the end of the line.
The syntax of the Single Line Comments is −

--Select all:
SELECT * FROM Customer;
   


The following example uses a single-line comment to ignore the end of a line:

SELECT * FROM Customer -- WHERE Address='Mumbai';
   



Multi-line Comments :

Multi-line comments begin with / * and end with * /.
Anny text between / * and * / will be ignored.
In PostgreSQL, a comment that starts with /* symbol and ends with */ and can be anywhere in your PostgreSQL statement.
The syntax of the Multi Line Comments is −

/*Select all the columns
of all the records
in the Customers table:*/
SELECT * FROM Customer;
   


The following example uses a comment to ignore part of a line:

SELECT CustomerName, /*City,*/ Address FROM Customer;   





Visit :


Discussion


* You must be logged in to add comment.