pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <shammat@gmx.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: interval data type
Date: Thu, 21 Jan 2021 22:30:33 +0100
Message-ID: <7592ec6a-b3d2-e376-ff16-af03120fcbc8@gmx.net> (raw)
In-Reply-To: <0c229ba17fe7eb51223ebd8bb90cdfff.squirrel@webmail.harte-lyne.ca>
References: <0c229ba17fe7eb51223ebd8bb90cdfff.squirrel@webmail.harte-lyne.ca>

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.







view thread (3+ messages)  latest in thread

Message-ID: <7592ec6a-b3d2-e376-ff16-af03120fcbc8@gmx.net>
Permalink:  ../7592ec6a-b3d2-e376-ff16-af03120fcbc8@gmx.net/
Also on:    postgresql.org/message-id/7592ec6a-b3d2-e376-ff16-af03120fcbc8@gmx.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: shammat@gmx.net
  Subject: Re: interval data type
  In-Reply-To: <7592ec6a-b3d2-e376-ff16-af03120fcbc8@gmx.net>
  References: <0c229ba17fe7eb51223ebd8bb90cdfff.squirrel@webmail.harte-lyne.ca> <7592ec6a-b3d2-e376-ff16-af03120fcbc8@gmx.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox