Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gKWbG-0003Tm-H0 for pgsql-general@arkaria.postgresql.org; Wed, 07 Nov 2018 22:47:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gKWbE-0000ep-TB for pgsql-general@arkaria.postgresql.org; Wed, 07 Nov 2018 22:47:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gKWbE-0000Q3-Fm for pgsql-general@lists.postgresql.org; Wed, 07 Nov 2018 22:47:00 +0000 Received: from mxc1.seznam.cz ([2a02:598:a::79:23]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gKWb6-0005Fv-E7 for pgsql-general@postgresql.org; Wed, 07 Nov 2018 22:46:59 +0000 Received: from email.seznam.cz by email-smtpc4a.ko.seznam.cz (email-smtpc4a.ko.seznam.cz [10.53.10.105]) id 5a207474a9f1f9905ab2fc25; Wed, 07 Nov 2018 23:46:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=email.cz; s=beta; t=1541630807; bh=xWnn/BmP/16qfoBSqvg+wsChIDUwlfJ2wG01pW7pq4c=; h=Received:Subject:To:References:From:Cc:Message-ID:Date:User-Agent: MIME-Version:In-Reply-To:Content-Type:Content-Language: Content-Transfer-Encoding; b=nL+CUQVVouLGx6LVQ9gCfrqzscoXCjYh7qqzfHeLRet9/Jtgemr4wwjNP8cdT4TNV bDUzZfGf+sA8L35efby/yrQ4og+E2JrzyPbUyDEFKusUXvjn/C707BCHUToEyu6swn pvyyG4D3mds4alp93WOeHYogTSVBt/jSBq/lhXfk= Received: from [192.168.0.110] (ip-94-112-39-7.net.upcbroadband.cz [94.112.39.7]) by email-relay14.ko.seznam.cz (Seznam SMTPD 1.3.102) with ESMTP; Wed, 07 Nov 2018 23:46:46 +0100 (CET) Subject: Re: Largest & Smallest Functions To: Ken Tanzer References: From: =?UTF-8?Q?Ond=c5=99ej_Bouda?= Cc: PG-General Mailing List Message-ID: Date: Wed, 7 Nov 2018 23:46:46 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: cs Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, > 2) Is there any particular reason functions like that aren't built > into Postgres? They seem like they would be useful. (Or maybe I > missed them?) LEAST() and GREATEST() expressions do the same thing as yours smallest() and largest(). See https://www.postgresql.org/docs/current/functions-conditional.html That might also answer the first question - just drop smallest() and largest() and you will get two functions instead of four :-) Now to be a little more serious, if you want a single function to both support variadic number of arguments AND all of them in a single array, how could the function decide whether smallest(ARRAY[1,2,3]) shall return 1 or ARRAY[1,2,3] (which is the smallest out of all arguments)? I would suggest not to declare such overloaded function even if it was possible, as it might confuse the reader easily. Instead, I would go for SELECT min(u) FROM unnest(ARRAY[1,2,3]) u or just define a separate least_array() / greatest_array() variant. Regards, Ondřej Bouda