Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 1BE2CB5DC56 for ; Mon, 29 Aug 2011 11:29:50 -0300 (ADT) 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 58802-05 for ; Mon, 29 Aug 2011 14:29:44 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from gw.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by mail.postgresql.org (Postfix) with ESMTP id CC916B5DC36 for ; Mon, 29 Aug 2011 11:29:43 -0300 (ADT) Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Mon, 29 Aug 2011 09:29:43 -0500 Message-Id: <4E5B5BFD02000025000407F6@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.1 Date: Mon, 29 Aug 2011 09:29:33 -0500 From: "Kevin Grittner" To: "Alexey Klyukin" Cc: Subject: Re: the '::' cast doesn't work in the FROM clause References: <4E5B449602000025000407D9@gw.wicourts.gov> <7B691F0D-A0E3-4195-98E7-F0C5833A2B74@commandprompt.com> <4E5B55C102000025000407F1@gw.wicourts.gov> <1804685E-C378-49E1-B12C-96078B221102@commandprompt.com> In-Reply-To: <1804685E-C378-49E1-B12C-96078B221102@commandprompt.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201108/173 X-Sequence-Number: 30985 Alexey Klyukin wrote: > On Aug 29, 2011, at 5:02 PM, Kevin Grittner wrote: > >> Alexey Klyukin wrote: >> >>> Function calls can appear in the FROM clause. (This is >>> especially useful for functions that return result sets, but any >>> function can be used.) This acts as though its output were >>> created as a temporary table for the duration of this single >>> SELECT command. >> >> It doesn't say that operators which provide equivalent >> functionality to functions can also be used. > > I agree, but why is it possible to use the type casting with CAST > there? Because the syntax is that of a function, which is allowed. > Doesn't this break the promise of equivalency between the > 'CAST .. ' and '::'? No. Equivalent functionality doesn't imply that the different syntax forms can be used in the same places; just that they do the same thing when used. This is hardly unique to casting. Comparison of two text values is done through the texteq function. test=# select val from texteq('a', 'a') as val; val ----- t (1 row) test=# select val from 'a' = 'a' as val; ERROR: syntax error at or near "'a'" LINE 1: select val from 'a' = 'a' as val; ^ test=# select val from (select 'a' = 'a') as val; val ----- (t) (1 row) > select val from CAST(random() as integer) as val; > val > ----- > 1 > (1 row) Right. A function is allowed as a from_item. Arbitrary expressions using operators which happen to provide equivalent services are not. -Kevin