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 1kC0fr-0003HQ-Px for pgsql-sql@arkaria.postgresql.org; Sat, 29 Aug 2020 13:13:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kC0fq-0001eJ-Iv for pgsql-sql@arkaria.postgresql.org; Sat, 29 Aug 2020 13:13:38 +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 1kC0fp-0001eC-Ef for pgsql-sql@lists.postgresql.org; Sat, 29 Aug 2020 13:13:38 +0000 Received: from mail-oln040092009037.outbound.protection.outlook.com ([40.92.9.37] helo=NAM04-BN3-obe.outbound.protection.outlook.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kC0fm-0007AW-1p for pgsql-sql@lists.postgresql.org; Sat, 29 Aug 2020 13:13:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fwIeG9RR3BX6ciowFjCKn4rGl/tfUtFfNiXRB9wzhB92GDVki1xmMCRcZsNq7lng/2Y6LMl9aAu1IjjZAU8s+P7Iq0jXWSTYnecSHuoCAuhA0lLCM40LzkYkyODvK/ciL32x9I5RhV75caRBqixi2k6DGUU+cZZwBdE4jWB0tpHKDpJTdl+otThWK/7Yve/TFPPFrWYX/dkRTrJUnmNIa4e91eQxY+wf01xrGkw4XW7gPy9QUaYD11qPPVQr8WdZ4u/BSnnDSONRnfkELenHRMwwLS7LUl7iOZrYBvR3r3N+jRv5k8ci73ADIZmlNOMRbnTPFCk70a2ZsX9axM2U1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3h05LVupedJSIbDqtV9vSheC+8PrkIviJM6VSWarm5U=; b=ZA1TWCPiRaecd7DtPnnvW4IDpjSylnbaTA34XEiFAjQUmkpn9dZlIXW89p8j7/j3CHnyseRbT+u5RIwD5bF89Yj/GM8rQvLzmF80ZZk/xfw008dCXX2SY8IpRNZGkVNJwOOLq1Y+xzsMm4eUdOWPW3rfcvyMGpqiiNGqGPfogtJx00iJWpuL8N+7FgPUi/Q2sXJsJgnH276XWLf1Wv5ohSbCzeLaWO/10rAMbQlUBtVtWR1jrCZwpnEYZAen2ipgKSYo+aqj4NrWQzEanayfXkI4cLkRCNL2dhLYi2rNAJR442BovB0Z0/9yD4Tf6O3tLA/jnNrq87rZp0oPV7D/iw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3h05LVupedJSIbDqtV9vSheC+8PrkIviJM6VSWarm5U=; b=VziVYRTCBcgvJW2AjXPgQ0qpYCP+GGyPCw9GfrP92lIWhLqVpo6arNfxShY7AnMJdBO6btjbPYQCwTZJBTj30i90eM1t0VlAvda5qnzKOTOQdSBkybGTPjo00Te6mvgc7Kcr1tFIN1HqBSeWgELsHWFP8B6G12O6FZzX26CAYhV2HKIuU2i+PfRAdloWWD7sVZcjmUlLOX/7WQa99mIFrIwB5NUaYrqdfqYv6zAgD/V/0OgRK7q0AVFXTRMmW465SsERKzdYK54Y7IWtdNyKLOuBvdWTFsEecX+pjNFEAiJUpr/loVrK8N0YywbAwF8tpZzGINplbBZwl7z9/fIdzQ== Received: from BN8NAM04FT054.eop-NAM04.prod.protection.outlook.com (2a01:111:e400:7e85::4e) by BN8NAM04HT219.eop-NAM04.prod.protection.outlook.com (2a01:111:e400:7e85::345) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.21; Sat, 29 Aug 2020 13:13:31 +0000 Received: from DM6PR06MB5562.namprd06.prod.outlook.com (2a01:111:e400:7e85::4e) by BN8NAM04FT054.mail.protection.outlook.com (2a01:111:e400:7e85::62) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Sat, 29 Aug 2020 13:13:31 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:74B93898C13623D46A60A2BF90BEBF258EC7A34E4409F22889ED9536BFD78923;UpperCasedChecksum:485913445CC2FD686463639B07FB0298AA248B7749CF7580C99C2D6BA7B20F33;SizeAsReceived:9076;Count:49 Received: from DM6PR06MB5562.namprd06.prod.outlook.com ([fe80::8d37:b8a9:bb0:624d]) by DM6PR06MB5562.namprd06.prod.outlook.com ([fe80::8d37:b8a9:bb0:624d%3]) with mapi id 15.20.3326.022; Sat, 29 Aug 2020 13:13:30 +0000 Subject: Re: value returned by EXTRACT, date_part To: Tom Lane Cc: "David G. Johnston" , pgsql-sql References: <3517945.1598665173@sss.pgh.pa.us> From: John Lumby Message-ID: Date: Sat, 29 Aug 2020 09:13:46 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 In-Reply-To: <3517945.1598665173@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-ClientProxiedBy: YT1PR01CA0041.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2e::10) To DM6PR06MB5562.namprd06.prod.outlook.com (2603:10b6:5:3e::12) X-Microsoft-Original-Message-ID: <84943e41-834b-b51d-76ff-218184e613a0@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by YT1PR01CA0041.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Sat, 29 Aug 2020 13:13:29 +0000 X-Microsoft-Original-Message-ID: <84943e41-834b-b51d-76ff-218184e613a0@hotmail.com> X-TMN: [jQC+H7CzVptXTKXGRhqgyFdtqUMDx8O9kTAqakYBAHAu9EcoCFBNQoGTrPZf8Ebr] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 49 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 99e85c95-8043-4723-9c3d-08d84c1d52b7 X-MS-TrafficTypeDiagnostic: BN8NAM04HT219: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 99WrCDb9EyOghbT3jgcW2vpyt/QYaqHf4bJMk1KUZgPHC0k1bprJZsybTAxdOKE/Tms27AS7HS+pnMPeTEx4DXu7UzvQ/jrnXwu4z+ai9a7NyjBNDS4tALRg00jBqG+yLpZ9zTzr70tk8vMAvHZ5zkREg2C2C/glyvgG03WbC/wtM9ic+Cb51KSDTBVlyebFGaERfikd9BfR83bCMVeMfQ== X-MS-Exchange-AntiSpam-MessageData: E3XM4SDmK8eKu9Oi5UsjemZhUoSXvRu4QDwXbjY7aTTaeRD0+NDdrwpHRqKtR8R9jvZez0NQPJ9UfC0ehS4jds7fIjG2FAmxRvqgSOpsSIjHU4nkP0gkHCiEtEkS42ffYG5/Kw6W/4neYHfI4EuVDNp1LN6s9DONJ5BG/IisbRmxaot4I8Q9F+x8DNXxhG/rgt1Nrsh60ltYoEC6+u4QGw== X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-Network-Message-Id: 99e85c95-8043-4723-9c3d-08d84c1d52b7 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2020 13:13:30.6447 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: BN8NAM04FT054.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8NAM04HT219 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Thanks Tom On 2020-08-28 21:39, Tom Lane wrote: > > 4.6.3 "Intervals" lays down basically the same sorts of rules for > intervals: they are made of component fields and only the seconds > field can have a fractional part. What is not clear to me is how the "components"  (aka "subfields") of an interval are defined. e.g. SELECT EXTRACT(days FROM INTERVAL '1 year 35 days 1 minute');  date_part -----------         35 ok,     it takes the interval modulo months (the next higher unit than the one I requested) and then rounds that down. But SELECT EXTRACT(days FROM INTERVAL '400 days 1 minute');  date_part -----------        400 oh!    no it doesn't ... > > PG does offer a nonstandard EPOCH "field" in EXTRACT, which tries > to convert the timestamp or interval as a whole to some number of > seconds. Possibly you could make use of that, perhaps after first > applying date_trunc, to get what you're after. The whole enterprise > is pretty shaky though; for example you cannot convert months to days > or vice versa without making fundamentally-indefensible assumptions. Yes!        That is exactly what I am looking for.    Actually for simplicity I think I don't need date_trunc; for this particular case of wanting to find the size of an interval, it is as simple as always requesting its epoch and working in double-precision seconds. Thanks! > > regards, tom lane > .