Comments
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.
Contribute to Docs
- 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.
Learn PostgreSQL on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Skill path
Design Databases With PostgreSQL
Learn how to query SQL databases and design relational databases to efficiently store large quantities of data.Includes 5 CoursesWith CertificateBeginner Friendly13 hours - Free course
Getting Started Off-Platform for Data Science
Learn how to setup Jupyter Notebooks and PostGRESQL and run data science projects on your own computer locally!Beginner Friendly1 hour