Re: interval data type - Mailing list pgsql-general

From Thomas Kellerer
Subject Re: interval data type
Date
Msg-id 7592ec6a-b3d2-e376-ff16-af03120fcbc8@gmx.net
Whole thread Raw
In response to interval data type  ("James B. Byrne" <byrnejb@harte-lyne.ca>)
List 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.





pgsql-general by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: autovacuum verbose?
Next
From: Christophe Pettus
Date:
Subject: Re: interval data type