How to comment out in PostgreSQL?

by giovanny.lueilwitz , in category: PHP Databases , 2 years ago

How to comment out in PostgreSQL?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers


by mac , 2 years ago


To comment out a line of code in PostgreSQL, you can use the -- symbol. Anything after -- on a line will be treated as a comment, and will not be executed by the PostgreSQL server.

For example:

SELECT * FROM users;  -- this is a comment

You can also use /* and */ to comment out multiple lines of code:

This is a multi-line comment
It can span multiple lines

Note that these commenting conventions are specific to PostgreSQL, and may not work in other SQL dialects.


by samara , 8 months ago


In addition to the -- and /* */ commenting methods mentioned above, PostgreSQL also allows another way to comment out code using the --#. This style of commenting is specifically designed to temporarily disable parts of a query using a specialized extension called "pg_hint_plan". Here's an example:


SELECT * FROM users --# WHERE id = 1;

In this example, the --# symbol is used to indicate a hint comment. The WHERE clause after the comment will be temporarily disabled and not executed.

It's worth mentioning that the --# commenting style requires the "pg_hint_plan" extension to be installed and enabled in your PostgreSQL database. If you don't have this extension, you can use the -- and /* */ style for commenting.