Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 37E9C133740B for ; Tue, 15 Feb 2011 03:41:24 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 53298-03 for ; Tue, 15 Feb 2011 07:41:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smadev.internal.net (host3.dynacom.ondsl.gr [62.103.35.211]) by mail.postgresql.org (Postfix) with ESMTP id 4EEAF133655C for ; Tue, 15 Feb 2011 03:41:15 -0400 (AST) Received: from smadev.internal.net (localhost.internal.net [127.0.0.1]) by smadev.internal.net (8.14.2/8.14.2) with ESMTP id p1F7fD1K081990; Tue, 15 Feb 2011 09:41:13 +0200 (EET) (envelope-from achill@matrix.gatewaynet.com) Received: from localhost (localhost [[UNIX: localhost]]) by smadev.internal.net (8.14.2/8.14.2/Submit) id p1F7fCG9081989; Tue, 15 Feb 2011 09:41:12 +0200 (EET) (envelope-from achill@matrix.gatewaynet.com) From: Achilleas Mantzios Organization: Dynacom Tankers Mgmt To: pgsql-sql@postgresql.org Subject: Re: SQL gotcha Date: Tue, 15 Feb 2011 09:41:11 +0200 User-Agent: KMail/1.9.7 Cc: "Dean Gibson (DB Administrator)" References: <4D59BAD5.4090306@ultimeth.com> In-Reply-To: <4D59BAD5.4090306@ultimeth.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <201102150941.12331.achill@matrix.gatewaynet.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.451 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_BRBL_LASTEXT=1.449 X-Spam-Level: X-Archive-Number: 201102/63 X-Sequence-Number: 35139 =CE=A3=CF=84=CE=B9=CF=82 Tuesday 15 February 2011 01:29:25 =CE=BF/=CE=B7 De= an Gibson (DB Administrator) =CE=AD=CE=B3=CF=81=CE=B1=CF=88=CE=B5: > As you all know, when you specify an alias for a table or column name,=20 > the keyword "AS" is usually optional. I personally like to always=20 > include the "AS" keyword, if for no other reason than readability, and I= =20 > presume that always using "AS" might catch some syntactic errors as well. >=20 > However, recently I ran across a statement where the optionality of the=20 > "AS" keyword caused me some grief: >=20 > SELECT ... FROM aaa LEFFT JOIN bbb WHERE ... >=20 > Note the (unintentional) misspelling of the keyword "LEFT". PostgreSQL=20 > took "LEFFT" to be an alias for table "aaa" and silently accepted the=20 > statement; naturally I did not get the results I expected !! >=20 > If PostgreSQL had an option to always require the "AS", that would have=20 > caught this error. Is there any interest in PostgreSQL having any=20 > "pedantic"-type options, like many C/C++ compilers do? >=20 Actually PostgreSQL seems to endorse the usage of "AS" more than the SQL st= andard requires. http://www.postgresql.org/docs/8.3/interactive/sql-select.html "The AS Key Word In the SQL standard, the optional key word AS is just noise and can be omit= ted without affecting the meaning.=20 The PostgreSQL parser requires this key word when renaming output columns b= ecause the type extensibility features=20 lead to parsing ambiguities without it. AS is optional in FROM items, howev= er. " =2D-=20 Achilleas Mantzios