Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZtoHO-0007jF-9K for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Nov 2015 02:58:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZtoHN-000075-LJ for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Nov 2015 02:58:29 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZtoGl-0007rR-BZ for pgsql-bugs@postgresql.org; Wed, 04 Nov 2015 02:57:51 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZtoGi-0004wx-Pk for pgsql-bugs@postgresql.org; Wed, 04 Nov 2015 02:57:49 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id tA42viYb010510; Tue, 3 Nov 2015 21:57:44 -0500 From: Tom Lane To: ryan.vilim@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13754: Postgres possibly accepts a typo as valid input In-reply-to: <20151103195949.2747.55003@wrigleys.postgresql.org> References: <20151103195949.2747.55003@wrigleys.postgresql.org> Comments: In-reply-to ryan.vilim@gmail.com message dated "Tue, 03 Nov 2015 19:59:49 +0000" Date: Tue, 03 Nov 2015 21:57:44 -0500 Message-ID: <10509.1446605864@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org ryan.vilim@gmail.com writes: > I recently found that postgres will accept the > SELECT -144mycol > to be equivalent to > SELECT -144 AS mycol. Yup. There are two things going on there: 1. "-144mycol" is read as three tokens, "-", "144", and "mycol". 2. AS is optional. > I haven't been able to find any other references to this being standard SQL. As best I can tell, the SQL spec says that in spec-conformant SQL there should be a space between "144" and "mycol", because it says Any may be followed by a . A shall be followed by a or a . and , , and all count as s. (White space is a .) On the other hand, this restriction seems a tad arbitrary, because quoted identifiers count as s. Which means that -144mycol isn't quite valid SQL, but -144"mycol" is gold-plated valid SQL. So you would need a rather curious set of assumptions about the abilities of your lexer in order to decide that the first case is ambiguous while the second isn't. You could maybe argue that the second case is more readable, but that argument seems a bit thin. In any case, the odds that we'd change this behavior in PG are nil; there's no real upside to doing so and we'd inevitably break a lot of existing applications if we did. As for #2 (AS being optional), that's required by spec as well. Personally I find it one of the dumbest syntax decisions in the whole language, but it's in the spec so we're stuck with it. > I think it might be a bug in postgres. You can argue whether it's a bug or not, but it's intentional behavior. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs