Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 68BF11336971 for ; Mon, 14 Feb 2011 19:55:01 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 68424-04 for ; Mon, 14 Feb 2011 23:54:53 +0000 (UTC) X-Greylist: delayed 00:25:22.308979 by SQLgrey-1.7.6 Received: from mail.mailpen.net (mail.mailpen.net [209.59.217.159]) by mail.postgresql.org (Postfix) with ESMTP id 8DBAC1337B79 for ; Mon, 14 Feb 2011 19:54:53 -0400 (AST) Received: from [172.20.1.171] (pool-98-117-107-200.sttlwa.fios.verizon.net [98.117.107.200]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.mailpen.net (Postfix) with ESMTP id 55A6E114149; Mon, 14 Feb 2011 15:29:30 -0800 (PST) Message-ID: <4D59BAD5.4090306@ultimeth.com> Date: Mon, 14 Feb 2011 15:29:25 -0800 From: "Dean Gibson (DB Administrator)" Organization: UltiMeth Systems User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: SQL gotcha Content-Type: multipart/alternative; boundary="------------040705040503010304000200" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-5 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 201102/62 X-Sequence-Number: 35138 This is a multi-part message in MIME format. --------------040705040503010304000200 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit As you all know, when you specify an alias for a table or column name, the keyword "AS" is usually optional. I personally like to always include the "AS" keyword, if for no other reason than readability, and I presume that always using "AS" might catch some syntactic errors as well. However, recently I ran across a statement where the optionality of the "AS" keyword caused me some grief: SELECT ... FROM aaa LEFFT JOIN bbb WHERE ... Note the (unintentional) misspelling of the keyword "LEFT". PostgreSQL took "LEFFT" to be an alias for table "aaa" and silently accepted the statement; naturally I did not get the results I expected !! If PostgreSQL had an option to always require the "AS", that would have caught this error. Is there any interest in PostgreSQL having any "pedantic"-type options, like many C/C++ compilers do? -- Mail to my list address MUST be sent via the mailing list. All other mail to my list address will bounce. --------------040705040503010304000200 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit As you all know, when you specify an alias for a table or column name, the keyword "AS" is usually optional.  I personally like to always include the "AS" keyword, if for no other reason than readability, and I presume that always using "AS" might catch some syntactic errors as well.

However, recently I ran across a statement where the optionality of the "AS" keyword caused me some grief:
SELECT ... FROM aaa LEFFT JOIN bbb WHERE ...
Note the (unintentional) misspelling of the keyword "LEFT".  PostgreSQL took "LEFFT" to be an alias for table "aaa" and silently accepted the statement;  naturally I did not get the results I expected !!

If PostgreSQL had an option to always require the "AS", that would have caught this error.  Is there any interest in PostgreSQL having any "pedantic"-type options, like many C/C++ compilers do?

-- 
Mail to my list address MUST be sent via the mailing list.
All other mail to my list address will bounce.
--------------040705040503010304000200--