Skip to content

Latest commit

 

History

History
51 lines (40 loc) · 1012 Bytes

different-ways-to-define-an-interval.md

File metadata and controls

51 lines (40 loc) · 1012 Bytes

Different Ways To Define An Interval

There are several different ways in PostgreSQL to define an interval data type. An interval is useful because it can represent a discrete chunk of time. This is handy for doing date math.

Here are four different ways to define an interval:

  1. Use the interval keyword with a string
> select interval '3 days';
 interval
----------
 3 days
(1 row)
  1. Cast a string to the interval type
> select '3 days'::interval;
 interval
----------
 3 days
(1 row)
  1. The @ operator is a finicky syntax for declaring an interval
> select @ 3 days;
 days
------
    3
(1 row)
  1. The make_interval function can take various forms of arguments to construct an interval
> select make_interval(days => 3);
 make_interval
---------------
 3 days
(1 row)

source