Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 4ED879552D4 for ; Tue, 28 Feb 2012 11:43:08 -0400 (AST) Received: from mahout.postgresql.org ([98.129.198.123]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S2PCj-0006d4-Sk for pgsql-bugs@postgresql.org; Tue, 28 Feb 2012 15:43:07 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S2PCW-0007dM-Iy for pgsql-bugs@postgresql.org; Tue, 28 Feb 2012 15:42:53 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1S2PCV-0007Nn-Sm for pgsql-bugs@postgresql.org; Tue, 28 Feb 2012 15:42:51 +0000 Date: Tue, 28 Feb 2012 15:42:51 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #6496: Why the SQL is not reported as incorrect? Is there a builtin column named "name"? To: pgsql-bugs@postgresql.org From: luciano@geocontrol.com.br X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/200 X-Sequence-Number: 32543 The following bug has been logged on the website: Bug reference: 6496 Logged by: Luciano Barcellos Email address: luciano@geocontrol.com.br PostgreSQL version: 8.4.8 Operating system: Debian Squeeze (2.6.32-5-amd64) Description: = -- Create and populate table CREATE TABLE public.is_this_a_bug ( "name" VARCHAR(50) ); INSERT INTO public.is_this_a_bug VALUES ( '270I' ); INSERT INTO public.is_this_a_bug VALUES ( '270V' ); INSERT INTO public.is_this_a_bug VALUES ( '520I' ); INSERT INTO public.is_this_a_bug VALUES ( '520V' ); INSERT INTO public.is_this_a_bug VALUES ( '900I' ); INSERT INTO public.is_this_a_bug VALUES ( '900V' ); -- Query table: Ok SELECT DISTINCT SUBSTRING(bug."name" FROM 1 FOR 3) FROM public.is_this_a_bug bug; -- Wrong SQL. Reports no syntax error but yields unexpected data SELECT s."name" FROM (SELECT DISTINCT SUBSTRING(bug."name" FROM 1 FOR 3) FROM public.is_this_a_bug bug) s; -- Fixed SQL. SELECT s."name" FROM (SELECT DISTINCT SUBSTRING(bug."name" FROM 1 FOR 3) AS "name" FROM public.is_this_a_bug bug) s;