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

Member

by mac , 2 years ago

@giovanny.lueilwitz 

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:

1
SELECT * FROM users;  -- this is a comment


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

1
2
3
4
/*
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.

Member

by samara , a year ago

@giovanny.lueilwitz 

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:


1


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.