Hi! When it comes to programming SQL, my newbie approach is to write my code in a file test.sql, which I test from within psql by usingmy_db=> \i /some/path/test.sql...and (once I'm satisfied with the code) copy and paste it to a different file that has the SQL I've written so far for the project.It's a rather cumbersome system, all the more so because I don't have a convenient way to comment out large chunks of code (which may include C-style comments).I'm thinking of something like the trick of surrounding C code with pairs of #if 0 and #endif, which effectively comments out code, even when it contains /* C-style comments */.Is there some similar trick for SQL code?
If your sole objective is to comment out large chunks of SQL code, which in turn may have multi-line comments, then the simplest trick is to comment them using /* multi-line */ itself!
The SQL standard, and Postgres, allow you to nest comments; some commercial RDBMS' do not provide this, and hence people think it's not possible in SQL.
So following is possible, and you can \include this file in psql with your desired results:
/* temporary big comment to test only one query, and ignore others
/* my first query */
select 'hello world';
/* my second query */
select 200*201;
/* my application's query */
select ename from emp where empid = 10;
end big comment */
/* Currently testing this query, and do not want the above queries to be
executed until I am finished with this. So, put everything above this
comment in a huge multi-line comment */
select ename, dname from emp, dept where emp.deptid = dept.deptid;
--
gurjeet[.singh]@EnterpriseDB.com
singh.gurjeet@{ gmail | hotmail | indiatimes | yahoo }.com
EnterpriseDB http://www.enterprisedb.com
17° 29' 34.37"N, 78° 30' 59.76"E - Hyderabad *
18° 32' 57.25"N, 73° 56' 25.42"E - Pune
37° 47' 19.72"N, 122° 24' 1.69" W - San Francisco
http://gurjeet.frihost.net
Mail sent from my BlackLaptop device