Wish: support "quarter" in Interval

Started by Richard Neillabout 5 years ago1 messagesbugs
Jump to latest
#1Richard Neill
rn214@cam.ac.uk

Hello,

May I make a request that "Quarter" should be treated as a valid
Interval (as a synonym for "3 months"), to be consistent with other date
functions that allow it, such as date_trunc() and extract() ?

#1. 'quarter' is valid for date_trunc() and extract()

SELECT date_trunc ('quarter', now());

date_trunc
------------------------
2021-01-01 00:00:00+00

SELECT EXTRACT ('quarter' FROM now());

date_part
-----------
1

#2. But, 'quarter' is invalid for interval

SELECT '1 quarter'::interval;
ERROR: invalid input syntax for type interval: "1 quarter"

I would expect it to give exactly the same result as for 3 months:

SELECT '3 months' :: interval;

interval
----------
3 mons

* As an aside: it might also be useful to support "half"
(which half of a year), or interval of 6 months,
and the interval of "fortnight" = 14 days.

I'm testing this on version 13.2:

SELECT version();

version
-------------------------------------------------------------------------
PostgreSQL 13.2 (Ubuntu 13.2-1) on x86_64-pc-linux-gnu, compiled by gcc
(Ubuntu 10.2.1-19ubuntu1) 10.2.1 20210206, 64-bit

Thank you very much for your consideration.

Richard