Re: Integer input functions for date and timestamp

From: Brendan Jurd <direvus(at)gmail(dot)com>
To: Peter Geoghegan <peter(dot)geoghegan86(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Integer input functions for date and timestamp
Date: 2010-10-22 19:15:20
Message-ID: AANLkTikQSy4jbQ3_X5y7SXB5VCHAzeaf2tOZTyV1_jQ_@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 23 October 2010 05:58, Peter Geoghegan <peter(dot)geoghegan86(at)gmail(dot)com> wrote:
> On 22 October 2010 19:45, Brendan Jurd <direvus(at)gmail(dot)com> wrote:
>> Without these functions (or some variation), a user wishing to
>> construct a date from integers can only assemble the date into a
>> string and then put that string through postgres' datetime parser,
>> which is totally perverse.
>
> What's wrong with to_timestamp() and to_date()? Sure, your functions
> might be marginally faster, but I don't think that it's likely to be a
> very performance sensitive area.
>

Hi Peter,

The answer to your question is in the paragraph I quoted from my OP
above. to_timestamp() and to_date() don't offer any non-retarded way
to get from integer values to datetime values. They are great if you
are coming from text, but if you already have integers they are lame.

Perhaps an example would be constructive. Would you rather do this:

datetime(2010, 10, 23, 6, 11, 0)

or this:

to_date(2010::text || '-' || 10::text || '-' || 23::text || ' ' ||
6::text || ':' || 11::text || ':' || 0::text, 'YYYY-MM-DD HH24:MI:SS')

The performance increase is nice, but as you say, this isn't likely to
be in a performance critical path. The main benefits are convenience,
simplicity and readability.

Cheers,
BJ

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2010-10-22 19:15:40 Re: Integer input functions for date and timestamp
Previous Message Robert Haas 2010-10-22 19:12:54 Re: Integer input functions for date and timestamp