Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create comments.md under postgresql #4540

Merged
54 changes: 54 additions & 0 deletions content/postgresql/concepts/comments/comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
Title: 'Comments'
Description: 'Comments in PostgreSQL are explanatory lines ignored by the compiler, enhancing code clarity and maintenance.'
Subjects:
- 'Code Foundations'
- 'Computer Science'
- 'Web Development'
Tags:
- 'Comments'
- 'Database'
- 'PostgreSQL'
CatalogContent:
- 'getting-started-off-platform-for-data-science'
- 'paths/design-databases-with-postgresql'
- 'paths/computer-science'
---

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:

```sql
-- This is a single-line comment
```

- Multi-line comment:

```sql
/*
This is a
multi-line comment
*/
```

## Example

Here's an example of how comments are used in PostgreSQL:

```sql
-- Selects employee IDs and their names from the employees table.
SELECT id, name
FROM 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.