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 1kW1uC-0002j1-LP for pgsql-general@arkaria.postgresql.org; Fri, 23 Oct 2020 18:35:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kW1u9-00066H-P7 for pgsql-general@arkaria.postgresql.org; Fri, 23 Oct 2020 18:35:09 +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 1kW1u9-000669-HA for pgsql-general@lists.postgresql.org; Fri, 23 Oct 2020 18:35:09 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kW1u2-00017J-S3 for pgsql-general@lists.postgresql.org; Fri, 23 Oct 2020 18:35:08 +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 09NIZ0U9222397; Fri, 23 Oct 2020 14:35:00 -0400 From: Tom Lane To: "David G. Johnston" cc: Nikhil Benesch , "pgsql-generallists.postgresql.org" Subject: Re: split_part for the last element In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Fri, 23 Oct 2020 11:20:50 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <222395.1603478100.1@sss.pgh.pa.us> Date: Fri, 23 Oct 2020 14:35:00 -0400 Message-ID: <222396.1603478100@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "David G. Johnston" writes: > On Fri, Oct 23, 2020 at 8:47 AM Nikhil Benesch > wrote: >> Is there another option I'm missing? Would there be interest in >> extending split part so that negative indices counted from the end, as >> in: >> split_part('foo bar baz', ' ', -1) -> 'baz' > I'm torn here because this would be the first usage of this concept in > PostgreSQL (I think). We already have some JSON functions that act like that, not to mention the left() and right() string functions, so I don't see that much of an argument against extending split_part to do it. > Tangentially, I noticed that we have a "starts_with" function but no > corresponding "end_with". > It's been a while but there used to be a systemic inertia working > against adding minor useful functions such as these. Part of the reason for that bias is that these one-off functions tend not to be very well thought out or complete :-(. The point that could be raised here is why we have split_part but not any corresponding regex-based splitter. regards, tom lane