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 1owLHH-0002DA-FS for pgsql-general@arkaria.postgresql.org; Sat, 19 Nov 2022 10:40:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1owLGI-0001jQ-8r for pgsql-general@arkaria.postgresql.org; Sat, 19 Nov 2022 10:39:50 +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 1owLGH-0001jH-SI for pgsql-general@lists.postgresql.org; Sat, 19 Nov 2022 10:39:49 +0000 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1owLGE-0001hc-Df for pgsql-general@postgresql.org; Sat, 19 Nov 2022 10:39:49 +0000 Received: by mail-ej1-x630.google.com with SMTP id gv23so18691679ejb.3 for ; Sat, 19 Nov 2022 02:39:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=XQanfZLidR1OwoHLLGW5e3EtEVTboyMkn+2OPaoKxpM=; b=Y6KvnxYifx2hJsGIfj/7ZpH0Ma6LeXFz9zTiVz34MorUyyrySVDZtS/JJBYqyJVO71 qefBia6S9u4mNWr2Lg1JNR5rUlrKQv8NifvOLx8c5K/HponxwvAcYaKk2dFV6uW/Ryil HlSLiJ07LOh1pMpyjXcZYC/izDMaLW2kTaTnmCfmwbA8I7qUy3Hu9shyZ+pHqikUAL2r 5WPbNhZW4c4hGu6nUDPM5H4pJn/AD0xdr2sJpjGcGfP+PooIQzwNHEWPLV9CJwwyKBcR WsQ31oPtgGYiA1Iz6TNAj8C1boOnCITga5gt1z8YsQMdE8d2rpnOFYg6cvQVL7dMer9D dj+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XQanfZLidR1OwoHLLGW5e3EtEVTboyMkn+2OPaoKxpM=; b=MZgQfyyILyf8xiOmOhpmVdkD9HvqkuvpSJRCB06JyY2T7Y28O1IN4RIVXORpB118qn djic7J+b7lk5G1yEWCDAYTl9uA2L7qgP2e/h//KTWTXQ5/FlzJwqXT8oI847qsGHwY1W Czb9W3vD91OvY6+cgPsrY+8/8D4kX8Y2JJwqTuSUXiMF1jSr+NArPRzfNpZoS5UMbz6i uDD96iPOYgqWBXa+MQcFJfiLC4QjisCOyHF1Ttc30Cq20jjXuUjOhH93hYa4LHgeRzE3 lVKE9yXza8tMrKOF5fPyaax4S4AK50IIHfoFMEsvEBtG3GukUSCD6IQtNqy9lm8E/OjK zeaw== X-Gm-Message-State: ANoB5pnuQVZQp3rxcmrKv3tFqWOvHou1qJYn9W7afWgNR57JeWMXbh+o /G/64PP8DF6vwfl7eh+dPQY= X-Google-Smtp-Source: AA0mqf5TFy7hDdlVufOlvOEyhTkoFFcj9swXw9tefeFFJEFvaUvYUJl01v4mZrj4KxdyMHwkeVkrnA== X-Received: by 2002:a17:906:6681:b0:7ae:732d:bc51 with SMTP id z1-20020a170906668100b007ae732dbc51mr9065262ejo.549.1668854385217; Sat, 19 Nov 2022 02:39:45 -0800 (PST) Received: from hollewijn.internal (217-19-30-105.dsl.cambrium.nl. [217.19.30.105]) by smtp.gmail.com with ESMTPSA id q13-20020a056402040d00b004614fd33789sm2798189edv.18.2022.11.19.02.39.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 19 Nov 2022 02:39:44 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Subject: Re: Duda sobre como imprimir un campo INTERVAL From: Alban Hertroys In-Reply-To: Date: Sat, 19 Nov 2022 11:39:43 +0100 Cc: Alejandro Baeza Rangel , pgsql-general@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <7DD6FF46-1F92-4E6B-A288-45A26021EE75@gmail.com> References: To: Ken Tanzer X-Mailer: Apple Mail (2.3608.120.23.2.7) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 19 Nov 2022, at 4:58, Ken Tanzer wrote: >=20 > On Thu, Nov 17, 2022 at 2:30 PM Alejandro Baeza Rangel = wrote: (=E2=80=A6) > don't fully understand it. But what really confuses me is the example = below. How can these two intervals be equal and still yield different = output in the to_char function? And as a practical matter, and for the = OPs question, how can you convert from one to the other of these "equal" = values? >=20 > WITH inters AS ( > SELECT > '1 day 2 hours'::interval AS i1, > '26 hours'::interval AS i2 > ) > SELECT > *, > to_char(i1,'HH24:MM:SS') AS i1_char, > to_char(i2,'HH24:MM:SS') AS i2_char, > i1=3Di2 AS "Equal?" > FROM inters; >=20 > i1 | i2 | i1_char | i2_char | Equal?=20 > ----------------+----------+----------+----------+-------- > 1 day 02:00:00 | 26:00:00 | 02:00:00 | 26:00:00 | t >=20 > Cheers, > Ken Those intervals are not identical. I think the reasoning is that due to = DST changes, =E2=80=981 day 2 hours=E2=80=99 is more specific than its = conversion to =E2=80=9926 hours=E2=80=99 (or 25 or 27 at DST change). And since you=E2=80=99re not converting the number of days in to_char, = that information gets lost. That problem doesn=E2=80=99t seem to arise in the OP=E2=80=99s question = (as far as I understand his question), he does have dates to base the = intervals on. However, converting the differences in dates to intervals = decouples the difference from the dates (the intervals could, for = example, subsequently be added to an entirely different date) and he = ends up in the same boat. It would seem that the way to do this is to convert the difference to = (seconds since) epoch and do the math to convert that to a character = string yourself. See for example: = https://stackoverflow.com/questions/341384/how-to-convert-an-interval-like= -1-day-013000-into-253000 That seems unnecessarily complicated, perhaps there is/could be a more = convenient method? I=E2=80=99m sort of thinking of a "relative timestamp = offset" type, that tracks an exact difference relative to a given = timestamp? Alban Hertroys -- There is always an exception to always.