pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: Alexey Klyukin <alexk@commandprompt.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: the '::' cast doesn't work in the FROM clause
Date: Mon, 29 Aug 2011 09:29:33 -0500
Message-ID: <4E5B5BFD02000025000407F6@gw.wicourts.gov> (raw)
In-Reply-To: <1804685E-C378-49E1-B12C-96078B221102@commandprompt.com>
References: <4E5B449602000025000407D9@gw.wicourts.gov>
	<7B691F0D-A0E3-4195-98E7-F0C5833A2B74@commandprompt.com>
	<4E5B55C102000025000407F1@gw.wicourts.gov>
	<1804685E-C378-49E1-B12C-96078B221102@commandprompt.com>

Alexey Klyukin <alexk@commandprompt.com> wrote:
> On Aug 29, 2011, at 5:02 PM, Kevin Grittner wrote:
> 
>> Alexey Klyukin <alexk@commandprompt.com> 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



view thread (13+ messages)  latest in thread

Message-ID: <4E5B5BFD02000025000407F6@gw.wicourts.gov>
Permalink:  ../4E5B5BFD02000025000407F6@gw.wicourts.gov/
Also on:    postgresql.org/message-id/4E5B5BFD02000025000407F6@gw.wicourts.gov

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: Kevin.Grittner@wicourts.gov, alexk@commandprompt.com
  Subject: Re: the '::' cast doesn't work in the FROM clause
  In-Reply-To: <4E5B5BFD02000025000407F6@gw.wicourts.gov>
  References: <4E5B449602000025000407D9@gw.wicourts.gov> <7B691F0D-A0E3-4195-98E7-F0C5833A2B74@commandprompt.com> <4E5B55C102000025000407F1@gw.wicourts.gov> <1804685E-C378-49E1-B12C-96078B221102@commandprompt.com> <4E5B5BFD02000025000407F6@gw.wicourts.gov>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox