Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 522959552D6 for ; Tue, 28 Feb 2012 17:47:26 -0400 (AST) Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S2UtG-0006je-IB for pgsql-bugs@postgresql.org; Tue, 28 Feb 2012 21:47:25 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q1SLl6oi025075; Tue, 28 Feb 2012 16:47:06 -0500 (EST) To: luciano@geocontrol.com.br cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6496: Why the SQL is not reported as incorrect? Is there a builtin column named "name"? In-reply-to: References: Comments: In-reply-to luciano@geocontrol.com.br message dated "Tue, 28 Feb 2012 15:42:51 +0000" Date: Tue, 28 Feb 2012 16:47:06 -0500 Message-ID: <25074.1330465626@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/203 X-Sequence-Number: 32546 luciano@geocontrol.com.br writes: > -- 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; This is not a bug, exactly, although I'll agree that it's surprising behavior. What is happening is that the system is taking s."name" as a coercion from the subquery's composite rowtype to the string type "name". We got enough complaints about that that 9.1 no longer does it, cf this release note entry: Disallow function-style and attribute-style data type casts for composite types (Tom Lane) For example, disallow composite_value.text and text(composite_value). Unintentional uses of this syntax have frequently resulted in bug reports; although it was not a bug, it seems better to go back to rejecting such expressions. The CAST and :: syntaxes are still available for use when a cast of an entire composite value is actually intended. There are also some possibly illuminating details here: http://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=543d22fc7423747afd59fe7214f2ddf6259efc62 regards, tom lane