Re: - operator overloading not giving expected result

Поиск
Список
Период
Сортировка
От Christoph Moench-Tegeder
Тема Re: - operator overloading not giving expected result
Дата
Msg-id YsgnPr6HCEXVsScF@elch.exwg.net
обсуждение исходный текст
Ответ на - operator overloading not giving expected result  (Rajesh S <rajesh.s@fincuro.com>)
Ответы Re: - operator overloading not giving expected result  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
## Rajesh S (rajesh.s@fincuro.com):

> We are migrating our database from Oracle to Postgresql.  In oracle we 
> have used this syntax "SELECT ('1999-12-30'::DATE) - 
> ('1999-12-11'::DATE)" to get difference between two dates as a integer 
> output (ex: 19).  But in Postgres the same query returns result as "19 
> days".

There's something fishy going on, as (date) - (date) returns integer
since a very long time (even the version 8.0 docs have that).
On the other hand, (timestamp) - (timestamp) gives an interval, so
first make sure you really got the data types right.

> CREATE OR REPLACE FUNCTION public.dt_minus_dt(
>      dt1 timestamp without time zone,
>      dt2 timestamp without time zone)

See? There's TIMESTAMP, not DATE.

>      LANGUAGE 'edbspl'

Is this really PostgreSQL or is it that fork - and if it's the fork,
does it behave the same way as stock PostgreSQL does? (I would be
surprised if that deviates in this place, but...).

>      SELECT DATE_PART('day', dt1::timestamp - dt2::timestamp)::integer 

And TIMESTAMP again.

Regards,
Christoph

-- 
Spare Space



В списке pgsql-general по дате отправления:

Предыдущее
От: Francisco Olarte
Дата:
Сообщение: Re: - operator overloading not giving expected result
Следующее
От: Tom Lane
Дата:
Сообщение: Re: - operator overloading not giving expected result