Re: - operator overloading not giving expected result - Mailing list pgsql-general

From Christoph Moench-Tegeder
Subject Re: - operator overloading not giving expected result
Date
Msg-id YsgnPr6HCEXVsScF@elch.exwg.net
Whole thread Raw
In response to - operator overloading not giving expected result  (Rajesh S <rajesh.s@fincuro.com>)
Responses Re: - operator overloading not giving expected result  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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 by date:

Previous
From: Francisco Olarte
Date:
Subject: Re: - operator overloading not giving expected result
Next
From: Tom Lane
Date:
Subject: Re: - operator overloading not giving expected result