MAK
MAK

Reputation: 7260

PostgreSQL 9.3: Add/Remove QUARTER to/from timestamp

I want to add the QUARTER to the TIMESTAMP in PostgreSQL 9.3 version.

My Try:

For adding:

SELECT TIMESTAMP '2016-01-01' + INTERVAL '01 QUARTER';

For remove:

SELECT TIMESTAMP '2016-01-01' - INTERVAL '01 QUARTER';
********** Error **********  
ERROR: invalid input syntax for type interval: "01 QUARTER"  
SQL state: 22007  
Character: 42

Upvotes: 5

Views: 4210

Answers (1)

Erwin Brandstetter
Erwin Brandstetter

Reputation: 658032

That's because quarter is not among supported units for interval input. The manual:

unit is microsecond, millisecond, second, minute, hour, day, week, month, year, decade, century, millennium, or abbreviations or plurals of these units;

Use '3 month' (or similar) instead:

SELECT timestamp '2016-01-01' + interval '3 month';

Upvotes: 10

Related Questions