Re: interval data type

From: Thomas Kellerer <shammat(at)gmx(dot)net>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: interval data type
Date: 2021-01-21 21:30:33
Message-ID: 7592ec6a-b3d2-e376-ff16-af03120fcbc8@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

James B. Byrne schrieb am 21.01.2021 um 22:22:
> What is the difference between interval(3)[] and simply interval(3)? Where in
> the documentation is the [] syntax discussed?

The [] denotes an array of intervals.

So in a column defined as interval[] you can store multiple intervals, just
like in an array of text (text[]), where you can store multiple strings.

This is discussed in the chapter about arrays:

https://www.postgresql.org/docs/current/arrays.html

> Also I do not understand under what circumstance one would use the interval
> type in place of a simple integer.

What would that integer represent? Seconds? Minutes? Hours? Fractional days?

Using an interval makes things a lot easier, because you can store any "duration"
in it without the need to know what the unit is that is stored in the column.

Also timestamp values and intervals go well together, but not timestamps and integers

You can add an interval to a timestamp and the result is a new timestamp.
If you stored the "duration" as integer, you would first need to convert the
integer to an interval.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Christophe Pettus 2021-01-21 21:46:10 Re: interval data type
Previous Message Peter Geoghegan 2021-01-21 21:29:33 Re: autovacuum verbose?