Re: Proposed changing the definition of decade for date_trunc and extract - Mailing list pgsql-hackers

From Mike Swanson
Subject Re: Proposed changing the definition of decade for date_trunc and extract
Date
Msg-id 1407048786.31613.2.camel@gmail.com
Whole thread Raw
In response to Re: Re: Proposed changing the definition of decade for date_trunc and extract  (Mike Swanson <mikeonthecomputer@gmail.com>)
Responses Re: Proposed changing the definition of decade for date_trunc and extract
List pgsql-hackers
On Fri, 2014-08-01 at 22:28 -0700, Mike Swanson wrote:
> I'd also argue that the current function basing the logic from
> definition #2 has limited use even when you want to use it for such.
> If you want to generate text for '(decades)s' you'd have to do:
>   SELECT extract('year' from date_trunc('decade', now())) || 's';
> Or with my patch:
>   SELECT floor(extract('year' from now()) / 10) || '0s';
> It's different, for sure, but I would actually think the second one is
> a bit less awkward.  Plus it's shorter :)

I'm responding to myself because I realized that what I wrote was a bit
silly.  The first and current example (which is invalidated by my patch)
should really be: SELECT extract('decade' from now()) || '0s';
which makes it the shorter and simpler version of the two.  I'll still
stand by my opinion that it's not an extremely useful function as it is.




pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: a fast bloat measurement tool (was Re: Measuring relation free space)
Next
From: Peter Geoghegan
Date:
Subject: Re: B-Tree support function number 3 (strxfrm() optimization)