Обсуждение: bug?

Поиск
Список
Период
Сортировка

bug?

От
Laurette Cisneros
Дата:
What is the difference between these two queries?  Is this a bug?

select case when current_timestamp < '2002-12-06'::date + 1
then 'yes'
else 'no'
end;

--> returns "yes"

select case when current_timestamp < '2002-12-06'::date + 1::interval
then 'yes'
else 'no'
end;

--> returns "no"

Thanks,

--
Laurette Cisneros
The Database Group
(510) 420-3137
NextBus Information Systems, Inc.
www.nextbus.com
----------------------------------
There's more to life than just SQL.


Re: bug?

От
Oskar Berggren
Дата:
Laurette Cisneros wrote:
> What is the difference between these two queries?  Is this a bug?
>

> select case when current_timestamp < '2002-12-06'::date + 1

> select case when current_timestamp < '2002-12-06'::date + 1::interval

Yes there is a difference:

select '2002-12-06'::date + 1;
   ?column?
------------
  2002-12-07
(1 row)


select '2002-12-06'::date + 1::interval;
         ?column?
------------------------
  2002-12-06 00:00:01+01
(1 row)


As you can see, 1::interval means one second, not one day.

/Oskar


Re: bug?

От
Laurette Cisneros
Дата:
Doh! Duh!

Thanks!
On Sat, 7 Dec 2002, Oskar Berggren wrote:

> Laurette Cisneros wrote:
> > What is the difference between these two queries?  Is this a bug?
> >
>
> > select case when current_timestamp < '2002-12-06'::date + 1
>
> > select case when current_timestamp < '2002-12-06'::date + 1::interval
>
> Yes there is a difference:
>
> select '2002-12-06'::date + 1;
>    ?column?
> ------------
>   2002-12-07
> (1 row)
>
>
> select '2002-12-06'::date + 1::interval;
>          ?column?
> ------------------------
>   2002-12-06 00:00:01+01
> (1 row)
>
>
> As you can see, 1::interval means one second, not one day.
>
> /Oskar
>

--
Laurette Cisneros
The Database Group
(510) 420-3137
NextBus Information Systems, Inc.
www.nextbus.com
----------------------------------
There's more to life than just SQL.


Re: bug?

От
Steve Crawford
Дата:
Just looks like to me that a non-qualified addition of one to a date data
type increments by one day and a non-qualified interval increments by seconds
(it's easier to strip off all the other junk in the query and just look at
what your date calculation is returning):

steve=# select '2002-12-06'::date + 1;
  ?column?
------------
 2002-12-07

steve=# select '2002-12-06'::date + 1::interval;
        ?column?
------------------------
 2002-12-06 00:00:01-08

steve=# select '2002-12-06'::date + '1 day'::interval;
        ?column?
------------------------
 2002-12-07 00:00:00-08


Cheers,
Steve



On Friday 06 December 2002 4:32 pm, Laurette Cisneros wrote:
> 2002-12-06'::date + 1