Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pWYnP-0001ro-P4 for pgsql-general@arkaria.postgresql.org; Mon, 27 Feb 2023 08:23:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pWYnN-000880-UG for pgsql-general@arkaria.postgresql.org; Mon, 27 Feb 2023 08:23:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pWYnN-00087r-F2 for pgsql-general@lists.postgresql.org; Mon, 27 Feb 2023 08:23:41 +0000 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pWYnL-00064q-Rh for pgsql-general@postgresql.org; Mon, 27 Feb 2023 08:23:40 +0000 Received: by mail-ed1-x536.google.com with SMTP id da10so22348047edb.3 for ; Mon, 27 Feb 2023 00:23:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=z5uvA75C5ZA0dtNYaEbsRP6PYgpOT+jt9Xfy37K7Wdg=; b=pfZkCleK5PIKP985rAz8caa3Zz2xPLGtDoIpMSla/4XEUU3x1//l8OZBr+GnFYjW4Q QXvWpJZlORtv/YRaBE5AadS01dhOr6IeFZiW7XUXxnJpKNtLIjDFRr9XKMa+uY4L25I4 /Uia2752I4pxa5iY4hdzh6MKfVvCKXEK6jbIolSJ7QFwSgqbsO2h/HRsXnb3tVMT6x4F oDvPm0Tp3hSxrDalo6SMkS4rALcz2aOT5/zh4ak9qhDnhUpKoHN6vfn1NC6tcPLhdQSs MJxCwGevJdko4XYk7Rg+zYfAxd1ETW4FrFtqlBtUGPA3XareOjJhOF0V+Ouw8XkhoJnl 3oWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=z5uvA75C5ZA0dtNYaEbsRP6PYgpOT+jt9Xfy37K7Wdg=; b=0AFUa8xXCr9f+/lOas0I1vV8mbuS4hqVIszsiO6HTpzW0C6LZ1BnVeD7DRy5VJrVQh mkpekF7lbDpJCbMXD/GZZ9Ii9P+coknI+X9BRyK0/oxfjuFYLgP+uvX0w140y5z1tYjO IJtel2B1Z6ru2VC5Htx0QHpG2xsskUi//KafVDf2EflalzZl5REcWax8Fv2PEmfYTZcc ggNSbgmQuC9Fw1NjWFj/pz+KUEjsIreuPOrtbjs14rfCh26CWdigJiTi5eW4MgyT9JF4 wcghtnuemeLfHlws19rC/qvXiKyd4I5OsTTqKGpTf0G573RBzJKlCcM5tuAG7iefXbnI GdDg== X-Gm-Message-State: AO0yUKXuiUkfU23VoT7p1aJNGJYBShXLBb8hyp5jbQEm7ldVyWdS6YbR I1kbDPaqZWiHWxThuz3hUSIt0LZua5b5vI/K X-Google-Smtp-Source: AK7set/0jV9+NUH3RWhPih6bhFSBgK2T1f7tRgOKoWB+XrrFn34coycK1ndgCrSnZk+gM1zxXOoVbg== X-Received: by 2002:a17:906:1912:b0:872:6bd0:d2b with SMTP id a18-20020a170906191200b008726bd00d2bmr32916415eje.45.1677486218707; Mon, 27 Feb 2023 00:23:38 -0800 (PST) Received: from dynamic-pd01.res.v6.highway.a1.net ([2001:871:5e:539:1b2c:c52a:475d:310c]) by smtp.gmail.com with ESMTPSA id qx27-20020a170906fcdb00b008bda61ff999sm2913104ejb.130.2023.02.27.00.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 00:23:38 -0800 (PST) Message-ID: <96ad392589f3f147b0b5dd240f4903cd58eb5bfb.camel@cybertec.at> Subject: Re: Interval in hours but not in days Leap second not taken into account From: Laurenz Albe To: PALAYRET Jacques , pgsql-general@postgresql.org Date: Mon, 27 Feb 2023 09:23:37 +0100 In-Reply-To: <1200461876.22810256.1677482775363.JavaMail.zimbra@meteo.fr> References: <1200461876.22810256.1677482775363.JavaMail.zimbra@meteo.fr> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 2023-02-27 at 07:26 +0000, PALAYRET Jacques wrote: > # An interval in " years months ... seconds " given in seconds by EXTRACT= (EPOCH ...) transtyped into INTERVAL : > SELECT (EXTRACT(EPOCH FROM ('3 years 2 months 1 day 10 hours 11 minutes 1= 2 seconds'::interval) ) || ' seconds')::interval ; > =C2=A0 interval > ------------- > =C2=A027772:11:12 >=20 > # The same interval in seconds formated with TO_CHAR() : > SELECT TO_CHAR((EXTRACT(EPOCH FROM ('3 years 2 months 1 day 10 hours 11 m= inutes 12 seconds'::interval) ) || ' seconds')::interval, ' yyyy mm dd_ hh2= 4-mi-ss ') ; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 to_char > --------------------------- > =C2=A0 0000 00 00_ 27754-11-12 >=20 > =3D> The result is given in hours ... (not in days ...). >=20 > It is logical that there are neither years nor months because they are no= t constant > (leap year or not; a month can contain 31 30 ... days). > I thought that days were eliminated because of the leap second (extra sec= onds > inserted in the UTC time scale); obviously, this is not the case. >=20 > # PostgreSQL does not take into account the additional second (leap secon= d) in some calendar days ; eg. 2016, 31 dec. : > SELECT to_timestamp('20170102 10:11:12','yyyymmdd hh24:mi:ss') - to_times= tamp('20161230 00:00:00','yyyymmdd hh24:mi:ss') intervalle ; > =C2=A0=C2=A0 intervalle > ----------------- > =C2=A03 days 10:11:12 > --> With postgreSQL, a calendar day is always 86,400 seconds long. >=20 > So, is there a reason for this (interval in hours ...) ? The best explanation I have is "daylight savings time". One day is not always 24 hours long. If you keep the interval in hours, the result is always correct (if you ignore leap seconds, which PostgreSQL doesn't account for). Yours, Laurenz Albe