Comments
thiennguyen.dev1 total contribution
Published May 14, 2024
Contribute to Docs
In PostgreSQL, comments are annotations added to SQL code to provide information about the code without affecting its execution. They are primarily used for documentation purposes and to enhance code readability. Comments in PostgreSQL can be single-line or multi-line and are initiated with --
for single-line comments and, /* */
for multi-line comments.
Syntax
- Single-line comment:
-- This is a single-line comment
- Multi-line comment:
/*This is amulti-line comment*/
Example
Here’s an example of how comments are used in PostgreSQL:
-- Selects employee IDs and their names from the employees table.SELECT id, nameFROM employees;/*Selects all columns from the departments table.This query retrieves detailed information about departments.*/SELECT *FROM departments;
Note: In the above example, comments are used to describe what the following SQL statement does. The PostgreSQL compiler will ignore these comments when executing the SQL code.
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.