Re: ISO something like "#if 0 ... #endif" for SQL code

From: "Kynn Jones" <kynnjo(at)gmail(dot)com>
To: "Gurjeet Singh" <singh(dot)gurjeet(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 18:12:15
Message-ID: c2350ba40803111112v6c233878s59f70187495178ed@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Mar 11, 2008 at 10:10 AM, Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>
wrote:

> 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.
>

Ah! Finally I see what Martin was getting at in his reply.

Well, among those who seem unaware of the standard is the author of the
Emacs SQL mode, because its syntax highlighting gets all messed up with
nested C-style comments...

Thanks for the tip!

Kynn

P.S. For any interested Emacs user: as it happens, it was pretty easy to
fix sql.el to allow C-style comments to nest. It just required adding a
couple of n's, to change the lines

(modify-syntax-entry ?/ ". 14" table)
(modify-syntax-entry ?* ". 23" table)

to

(modify-syntax-entry ?/ ". 14n" table)
(modify-syntax-entry ?* ". 23n" table)

(actually either one of the two changes would have sufficed) in the syntax
table definition

(defvar sql-mode-syntax-table
(let ((table (make-syntax-table)))
;; C-style comments /**/ (see elisp manual "Syntax Flags"))
(modify-syntax-entry ?/ ". 14" table)
(modify-syntax-entry ?* ". 23" table)
;; double-dash starts comments
(modify-syntax-entry ?- ". 12b" table)
;; newline and formfeed end comments
(modify-syntax-entry ?\n "> b" table)
(modify-syntax-entry ?\f "> b" table)
;; single quotes (') delimit strings
(modify-syntax-entry ?' "\"" table)
;; double quotes (") don't delimit strings
(modify-syntax-entry ?\" "." table)
;; backslash is no escape character
(modify-syntax-entry ?\\ "." table)
table)
"Syntax table used in `sql-mode' and `sql-interactive-mode'.")

(I also had to restart Emacs to get this change to have an effect. Just
executing the revised definition was not enough. Maybe there's a way to do
achieve the same without restarting, but I couldn't think of it.)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kynn Jones 2008-03-11 18:14:52 Re: ISO something like "#if 0 ... #endif" for SQL code
Previous Message CaseT 2008-03-11 17:51:21 How to convert postgres timestamp to date: yyyy-mm-dd