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 that are ignored by the compiler. They are used to describe the functionality of SQL statements, or to temporarily disable a piece of SQL code. Adding comments to your SQL scripts is considered a best practice, as it makes your code easier to understand and maintain.'
thiennguyen93 marked this conversation as resolved.
Show resolved Hide resolved
Subjects:
- 'Web Development'
- 'Computer Science'
Tags:
- 'Comments'
- 'Documentation'
thiennguyen93 marked this conversation as resolved.
Show resolved Hide resolved
CatalogContent:
- 'getting-started-off-platform-for-data-science'
- 'paths/design-databases-with-postgresql'
- 'paths/computer-science'
---

**Comments** are text placed inside code that is not executed. They are intended as documentation or explanation of the code they are a part of.
thiennguyen93 marked this conversation as resolved.
Show resolved Hide resolved

## Syntax

In PostgreSQL, you can use either single-line or multi-line comments.

- Single-line comments start with `--` and end at the end of the line.
thiennguyen93 marked this conversation as resolved.
Show resolved Hide resolved

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

- Multi-line comments start with `/*` and end with `*/`.
thiennguyen93 marked this conversation as resolved.
Show resolved Hide resolved

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

## Example

Here's an example of how you can use comments in PostgreSQL:
thiennguyen93 marked this conversation as resolved.
Show resolved Hide resolved

```sql
-- This is a single-line comment
SELECT *
FROM employees; -- This comment is at the end of the line

/*
This is a multi-line comment
that spans multiple lines
*/
SELECT *
FROM departments;
```
thiennguyen93 marked this conversation as resolved.
Show resolved Hide resolved

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.
thiennguyen93 marked this conversation as resolved.
Show resolved Hide resolved