SQL Comments
In SQL, comments are used to leave notes or explanations inside your queries. PostgreSQL ignores comments when it runs the query.
Single-line comment
Start a line with -- (two hyphens):
-- This is a single-line comment
SELECT name FROM employees WHERE id = 1;
Multi-line comment
Wrap the comment with /* ... */:
/*
This is a multi-line comment.
It spans multiple lines.
*/
SELECT name FROM employees WHERE id = 1;
Inline comment
You can also put a comment in the middle of a query. This is helpful to turn off part of a query for a moment:
SELECT name /*, age */ FROM employees WHERE id = 1;
Output:
name
-------
Alice
(1 row)
Here, , age is inside the comment, so the age column is not selected. Only name is returned.
Don't worry about WHERE id = 1 yet. It keeps the result to one row, and you will learn it soon.
In the problems, you will often see comments that explain what you need to do. Comments are a clear way to give instructions without changing how the query runs.