Skip site navigation (1) Skip section navigation (2)

Re: inconsistent automatic casting between psql and function

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Richard Huxton <dev(at)archonet(dot)com>, Stefano Buliani <stefano(at)covestor(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: inconsistent automatic casting between psql and function
Date: 2008-12-10 13:33:29
Message-ID: 200812101333.mBADXT924998@momjian.us (view raw or flat)
Thread:
Lists: pgsql-sql
Tom Lane wrote:
> Richard Huxton <dev(at)archonet(dot)com> writes:
> > That's because a quoted literal isn't necessarily a timestamp. Without
> > context it could be anything, and in the context of comparing to a date
> > the planner probably tries to make it a date.
> 
> I think the real point here is this:
> 
> regression=# select '2008-12-09 02:00:00'::date;
>     date    
> ------------
>  2008-12-09
> (1 row)
> 
> ie, when it does decide that a literal should be a date, it will happily
> throw away any additional time-of-day fields that might be in there.
> Had it raised an error, Stefano might have figured out his mistake
> sooner.
> 
> ISTM we deliberately chose this behavior awhile back, but I wonder
> whether it does more harm than good.

Well, it seems fine to me because it works just like the cast of a float
to an integer:

	test=> select 1.23432::integer;
	 int4
	------
	    1
	(1 row)

-- 
  Bruce Momjian  <bruce(at)momjian(dot)us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

In response to

pgsql-sql by date

Next:From: Pascal TufenkjiDate: 2008-12-10 14:33:07
Subject: Is there a bug in PostgreSQL ?
Previous:From: Allan KamauDate: 2008-12-10 12:46:33
Subject: Collapsing (select) row values into single text field.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group