From: Christoph Moench-Tegeder <cmt@burggraben.net>
To: Rajesh S <rajesh.s@fincuro.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: - operator overloading not giving expected result
Date: Fri, 8 Jul 2022 14:46:54 +0200
Message-ID: <YsgnPr6HCEXVsScF@elch.exwg.net> (raw)
In-Reply-To: <7f97243d-db62-199a-8412-5637963d117e@fincuro.com>
References: <7f97243d-db62-199a-8412-5637963d117e@fincuro.com>
## 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
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-general@postgresql.org
Cc: cmt@burggraben.net, rajesh.s@fincuro.com
Subject: Re: - operator overloading not giving expected result
In-Reply-To: <YsgnPr6HCEXVsScF@elch.exwg.net>
References: <7f97243d-db62-199a-8412-5637963d117e@fincuro.com> <YsgnPr6HCEXVsScF@elch.exwg.net>
* 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