From: | "Gurjeet Singh" <singh(dot)gurjeet(at)gmail(dot)com> |
---|---|
To: | "Kynn Jones" <kynnjo(at)gmail(dot)com> |
Cc: | "pgsql-general General" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: ISO something like "#if 0 ... #endif" for SQL code |
Date: | 2008-03-11 14:10:39 |
Message-ID: | 65937bea0803110710l50090af8xca54ecb2050288f1@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mon, Mar 10, 2008 at 9:20 PM, Kynn Jones <kynnjo(at)gmail(dot)com> wrote:
>
>
>
> 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 using
>
> my_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[(dot)singh](at)EnterpriseDB(dot)com
singh(dot)gurjeet(at){ 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
Mail sent from my BlackLaptop device
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2008-03-11 15:09:37 | Re: Database OID xxxxx now seems to belong to "foo" |
Previous Message | Gauthier, Dave | 2008-03-11 13:58:30 | Re: Database OID xxxxx now seems to belong to "foo" |