pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gavin Flower <GavinFlower@archidevsys.co.nz>
To: Huan Ruan <huan.ruan.it@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: DateDiff() function
Date: Thu, 11 Jul 2013 18:18:57 +1200
Message-ID: <51DE4E51.3050702@archidevsys.co.nz> (raw)
In-Reply-To: <CAD1stZuwG5fx4YJ+dyFRuxEaCmYo+nUWJvwuP-=FUTEA463PdQ@mail.gmail.com>
References: <CAD1stZuwG5fx4YJ+dyFRuxEaCmYo+nUWJvwuP-=FUTEA463PdQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

On 11/07/13 17:17, Huan Ruan wrote:
> Hi Guys
>
> We are migrating to Postgres. In the current system, we use datediff() 
> function to get the difference between two dates, e.g. datediff 
> (month, cast('2013-01-01' as timestamp), cast('2013-02-02' 
> as timestamp) returns 1.
>
> I understand that Postgres has Interval data type so I can achieve the 
> same with Extract(month from Age(date1, date2)). However, I try to 
> make it so that the existing SQL can run on both databases without 
> changes. One possible way is to add a datediff function to Postgres, 
> but the problem is that month/day/year etc is a keyword not a string 
> like 'month'. I noticed that Postgres seems to convert Extract(month 
> from current_timestamp) to date_part('month', current_timestamp), you 
> can also do Extract('month' from current_timestamp). So it seems 
> internally, Postgres can do the mapping from month to 'month'. I was 
> wondering if there is a way for me to do the same for the datediff() 
> function? Any other ideas?
>
> Thanks
> Huan
Purely out of curiosity, could you tell us what database software you 
are moving from, as well as a rough idea of the size of database, type 
and volume of database queries?

It would also be of interest to know what postgres features in 
particular were the biggest motivations for change, and any aspects that 
gave you cause for concern - obviously overall, it must have come across 
as being better .

I strongly suspect that answering these questions will have no direct 
bearing on how people will answer your query! :-)


Cheers,
Gavin

view thread (12+ messages)

Message-ID: <51DE4E51.3050702@archidevsys.co.nz>
Permalink:  ../51DE4E51.3050702@archidevsys.co.nz/
Also on:    postgresql.org/message-id/51DE4E51.3050702@archidevsys.co.nz

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: GavinFlower@archidevsys.co.nz, huan.ruan.it@gmail.com
  Subject: Re: DateDiff() function
  In-Reply-To: <51DE4E51.3050702@archidevsys.co.nz>

* 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