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 1kW20y-0002zw-Eb for pgsql-general@arkaria.postgresql.org; Fri, 23 Oct 2020 18:42: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 1kW20x-00047O-Cl for pgsql-general@arkaria.postgresql.org; Fri, 23 Oct 2020 18:42:11 +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 1kW20x-00047H-5C for pgsql-general@lists.postgresql.org; Fri, 23 Oct 2020 18:42:11 +0000 Received: from mail-ej1-x642.google.com ([2a00:1450:4864:20::642]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kW20v-0001AR-2k for pgsql-general@lists.postgresql.org; Fri, 23 Oct 2020 18:42:10 +0000 Received: by mail-ej1-x642.google.com with SMTP id dt13so3681995ejb.12 for ; Fri, 23 Oct 2020 11:42:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=JZ4/sfj5NBAWBn3/Ef3B8BCnCTqqjt1Vi66NN129+Aw=; b=OHO6+/ecOTr/xFIHmU/oHzABc66f4NRVRAN+a0L9r/cxv6HEkIJyvHnusLn8QlkWYD AN2zr3/4rToBx96Ab8NQto/k5y17F4WZSZnYpbJ75YuJaJSHoUsaVaErHLB9HlE05jHI pWiYa64D61fHazAVipapn9lxLMkA1O7lFP7UV+vahB2C1txI+o1tI5hZtgssKlXCrTeW fZrpARhw0HgReSkmZdZuPayitdhHjrshhKCcEUTVer/eW9ncra8fKubxlraQNe8ODwi6 X4P5GAB+m7zUFdttkevZieubq+ljKDoahOZvcyNvgwGLk/x/IiztSVqy30eJlwE/m0PA DA6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=JZ4/sfj5NBAWBn3/Ef3B8BCnCTqqjt1Vi66NN129+Aw=; b=ghRtYeHwKAzcBBPt1qlKX6AKIiuoekgW+C3f0FUc4D+2BTARnKnRMru3JavwTvPn3h n+U6dhnecv6TDtNDv7Rr9zW1WUw+4SqtTWcWsS+5HzZOXZHjf82phVcv/sIe4eXKc6bE 8pX4uLkO5wXNMHMiFSj/NAT/rcjmo3nhEAM7uCYfDmkUqbDG8hvMY8b0QgJpuE/lPIcO KMM5sHr/upPLccH/MOV+ceQ5+MxcjCE8tgIfjNO3CWZ7BUzUTAVLtAr3L9TKQ+LKISon y1CTUDxzCAwCQWGsSbHYgUPISM03P79u2uNFFZeF1qQrluLs75xtD+Olz+dOE7EqtbQN +pjw== X-Gm-Message-State: AOAM532XEpqgNYIZ5OJef4cekPxC0n4Fj2eAom6r5nwu/ICIYMoLxSTh uxo3fAR9p0VoUb8SA/f3IjN2sekBQfbQ5RqwiqI= X-Google-Smtp-Source: ABdhPJwMS+V9HLkNnmoqGFrBlw5tuzPCVqcpFSRiibDU2xC9+UJwMZF5+a3GVAghSzkOw1dtL/1hpP79qr3RTs4VcTA= X-Received: by 2002:a17:906:7844:: with SMTP id p4mr3293203ejm.26.1603478527944; Fri, 23 Oct 2020 11:42:07 -0700 (PDT) MIME-Version: 1.0 References: <222396.1603478100@sss.pgh.pa.us> In-Reply-To: <222396.1603478100@sss.pgh.pa.us> From: Nikhil Benesch Date: Fri, 23 Oct 2020 14:41:57 -0400 Message-ID: Subject: Re: split_part for the last element To: Tom Lane Cc: "David G. Johnston" , "pgsql-generallists.postgresql.org" Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Oct 23, 2020 at 2:35 PM Tom Lane wrote: > > "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. Oh, I didn't realize left and right already worked this way. That makes this design much more compelling, at least to me. If the consensus is this extension is ok, I'd be happy to prepare a patch.