Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rngZp-00EX0F-3O for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Mar 2024 15:13:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rngZn-004Wrz-68 for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Mar 2024 15:12:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rngZm-004Wrr-Nh for pgsql-hackers@lists.postgresql.org; Fri, 22 Mar 2024 15:12:59 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rngZj-005rwS-Mc for pgsql-hackers@lists.postgresql.org; Fri, 22 Mar 2024 15:12:58 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 42MFCt9q906077; Fri, 22 Mar 2024 11:12:55 -0400 From: Tom Lane To: Aleksander Alekseev cc: pgsql-hackers@lists.postgresql.org, =?UTF-8?Q?Viliam_=C4=8Eurina?= Subject: Re: MIN/MAX functions for a record In-reply-to: References: Comments: In-reply-to Aleksander Alekseev message dated "Fri, 22 Mar 2024 18:02:29 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <906075.1711120375.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 22 Mar 2024 11:12:55 -0400 Message-ID: <906076.1711120375@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Aleksander Alekseev writes: >> In my queries I often need to do MIN/MAX for tuples, for example: >> SELECT MAX(row(year, month)) >> FROM (VALUES(2025, 1), (2024,2)) x(year, month); >> This query throws: >> ERROR: function max(record) does not exist >> Was this ever discussed or is there something preventing the implementa= tion? > I believe it would be challenging to implement max(record) that would > work reasonably well in a general case. As long as you define it as "works the same way record comparison does", ie base it on record_cmp(), I don't think it would be much more than a finger exercise [*]. And why would you want it to act any differently from record_cmp()? Those semantics have been established for a long time. regards, tom lane [*] Although conceivably there are some challenges in getting record_cmp's caching logic to work in the context of an aggregate.