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.96) (envelope-from ) id 1w4yPP-002lGT-0S for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 09:50:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w4yPN-005k2d-1w for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 09:50:46 +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.96) (envelope-from ) id 1w4yPN-005k2U-0c for pgsql-hackers@lists.postgresql.org; Tue, 24 Mar 2026 09:50:45 +0000 Received: from mail-vk1-xa35.google.com ([2607:f8b0:4864:20::a35]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w4yPL-00000000lna-2sAU for pgsql-hackers@postgresql.org; Tue, 24 Mar 2026 09:50:44 +0000 Received: by mail-vk1-xa35.google.com with SMTP id 71dfb90a1353d-56739adfa1aso3733148e0c.0 for ; Tue, 24 Mar 2026 02:50:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774345843; cv=none; d=google.com; s=arc-20240605; b=MqEFZz71oygsD8LmgtDudw2bUSwU45Jz7T4ikvJkBytfWkxHl78BRxCEtwyM3pcUEu yt81yxKDh3ru0j6xPRYKgnA5dqAaksadDzepUsTNCW/kzo+QuQ1ozx2773sDgS9RSPlN kAVhIafYCO6/VTXq8Z6t9cA7gCuO2Urj7P4TcrRlUhU5riIT/bFkapvQNN7fEVXKXLrv BAIIMfBoWELm4GeetUKFo9NUgLFmFfpTEkkDBLjg1HHZdpF8mLO/ShM6B2VYMIQqUeQg HpSKZPotH2CdIovbUGcxlJftffZ/w6mqQwYgc79YQKadUrBSp4fEp6fceitSDCgr9fCD tQUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=NxlpGPJ1RfPJbdVNrTJ/b6qe034puGoGMD8Hcf0//0A=; fh=QtgNekqGYClJiaiFFVlVFTxdSI82FndRfhpgwazW4vw=; b=FMTwsb2tFKklw0UbvIYanoeTdyMEpAbY+XNyT4T6CEZpKniWXiAOyt/KCrpYjwqbH1 YeKRcLCtc3sgnAVk+Hu+afkaB5u28tU44mz7F5ikbOBsJVhGOljIc0J7KLJEnQOEaeNK mUyFDdBu1DnQW1qTK4b6w0JEvBLM9D9Wg5YlwJrnbyb4v79oCPLU0ymquK6mSEhjIMvS VQdRTkZSdwVgjds+lsntdBxepu/OzoSmu8gIF6o1sKt9REksinwVVQusQfNfYNEo0uiQ UDnEYsky8/cJEs3twnNEEosY10GnjbBwor0KZiXnYtnqW9ZgA+HhlHQLNe2B1LSWele0 EY6g==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774345843; x=1774950643; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=NxlpGPJ1RfPJbdVNrTJ/b6qe034puGoGMD8Hcf0//0A=; b=NgHrTFOHbbJSZ8AOrv1uMJKAdookrEBSr31psi2hmgJjMKkeSwDqO9yNVqsFT9KZbi pJl/0KrwZ7COfJxo5csiQ44ASiwmIzcc3vrxlIN+TU8eEqqfuEiPUZsnZ0TQsKxjDIOL ztLqIJNTqC3Ol5W2l4qx2h8sSYn6elS1STT2ZOMe0XLcsmjnqZGJiysFg3QXYOH6DZez Uk5RNQVXZ9MLwY03btUoGL3u6zdCIi70jCAhu/PZAPSp1qVUKxfF/nfG4sGwvtr/e9n8 QO6qSuctrylZgAjDtj5uDiVugb8xhgUGfqfhsKG/MiZcaT3RBOAK0LIuweyAv1S84qBF LeSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774345843; x=1774950643; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=NxlpGPJ1RfPJbdVNrTJ/b6qe034puGoGMD8Hcf0//0A=; b=rK2/i2bpsMfD00OcqwztYKnUSA4f1svB7ExyXGLaJlgbOpqWBYzacoPbiGE8N7NMod 6SZ9aZAPktSZM2JLSCFbBkbairfyfGf9zC1ph9FGEF7SA70hxisU05owOZbcsnpD7Jfs FzyGOD2H5f9pIkr1d5asYl5HhyiUE1PgiQw4KKAJusl7XdlKaTHpwqV73K3XG4/10bTY Bldy1nN4DvI10DD6DSeqhtwQGgKCRqx/qQsLwSg6BY1IISjx9H8O64B6zctPHz7xmJud JVO5ViHSAlQwyGhRxnnZLjqmLuv+g+DZn6+7bVOv0TNsgLbPWLH4zgonhku4ySFG6H+X g7Cg== X-Gm-Message-State: AOJu0Yzv+BD/B579XkznFwQ0HGetSDG9/ecHJIv4mFVGAsxiQ3UmqB5c w4nGy7H88pUjvwgn0xFb+JhQyfm99Dc3t718y6rDe7sqyFmveCu9v8pBKMVWLVjPgV9os/Cs2yz 6pOHB6r+Za46muE4ggq2jGJi39FFwXg== X-Gm-Gg: ATEYQzz4PclgZM70CZdISX9Tug696bZNl6o1cHvuPbVUL2AesIAWdXfzKmwljEtfYdK lq7gtF355exjITs6bAfqmSkoI9oGjuIRP7czCn7I887FfjXTka7FcWjjL0VKvoMw9BNxiC18MH5 KqVJsA7WT32hpEMIWNaxoYQHUXtqAs7jtOaNhFL54h4XcS+km7vz/3BQuA6dWiGMZkpcuK5bVnE EWzZg3QMGuwIi/ipUu28S8OPc7VOAZflzV6U8kSH/LsKsmyaE5xBxl5w/RY/GewlsrTCYYKpCWo YkniQrLKMCvMH8ScXg== X-Received: by 2002:a05:6122:d29:b0:56b:8ba0:fd6a with SMTP id 71dfb90a1353d-56cde1c5480mr8075399e0c.0.1774345842649; Tue, 24 Mar 2026 02:50:42 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Rushabh Lathia Date: Tue, 24 Mar 2026 15:20:31 +0530 X-Gm-Features: AQROBzBsAV-H-E-qVdrsKdE7MIue8R7hafRdZLgDCni4_WX1uY6_vMoTH-1p_g4 Message-ID: Subject: Re: ORDER BY ALL To: Kirill Reshke Cc: PostgreSQL Hackers Content-Type: multipart/alternative; boundary="000000000000a8ee1f064dc21586" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000a8ee1f064dc21586 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 24, 2026 at 1:32=E2=80=AFPM Kirill Reshke wrote: > On Tue, 24 Mar 2026 at 11:27, Rushabh Lathia > wrote: > > > > Hi hackers, > > > > Please find the attached patch, to implement the ORDER BY ALL clause. > > Commit ef38a4d97, implemented GROUP BY ALL clause, and this > > feature follows the same pattern. > > > > ORDER BY ALL is a form of ORDER BY that automatically adds all > > non-junk columns from the SELECT target list to the ORDER BY clause. > > > > This implementation supports: > > - ORDER BY ALL (default ascending order) > > - ORDER BY ALL ASC > > - ORDER BY ALL DESC > > - ORDER BY ALL NULLS FIRST/LAST > > - ORDER BY ALL ASC/DESC NULLS FIRST/LAST > > > > The syntax works by creating a marker SortBy node with a NULL > > node pointer that carries the sort direction and nulls ordering. > > During query transformation, this marker is detected and expanded > > to order by all non-junk columns in the target list with the > > specified direction. > > > > Implementation details: > > - gram.y: Added ORDER BY ALL grammar with optional ASC/DESC and NULLS > > in both main sort_clause and PLpgSQL_Expr rules > > - parse_clause.c: Implemented ORDER BY ALL expansion logic that iterate= s > > over target list columns > > - analyze.c: Updated to pass orderByAll flag through transformation > > - parsenodes.h: Added orderByAll boolean to SelectStmt and Query > > - ruleutils.c: Added deparsing support for ORDER BY ALL that preserves > > sort direction and NULLS ordering in view definitions, including prop= er > > handling of implicit vs explicit ordering > > > > Please take a look at the attached patch and let me know your thoughts. > > > > Thanks, > > Rushabh Lathia > > www.EnterpriseDB.com > > > > Hi! What about SQL standard compatibility? ef38a4d97 was merged only > after the SQL committee accepted GROUP BY ALL, there was discussion a > few years before [0] which ended up in nothing because of SQL > standard... So I wonder what is perspective of this thread > > > [0] > https://www.postgresql.org/message-id/CAAhFRxjyTO5BHn9y1oOSEp0TtpTDTTTb7H= JBNhTG%2Bi3-hXC0XQ%40mail.gmail.com Thanks a lot for sharing this. I was not aware that ORDER BY ALL is not ye= t part of SQL Standards (my bad). > > > -- > Best regards, > Kirill Reshke > --=20 Rushabh Lathia --000000000000a8ee1f064dc21586 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Tue, Mar 24,= 2026 at 1:32=E2=80=AFPM Kirill Reshke <reshkekirill@gmail.com> wrote:
On Tue, 24 Mar 2026 at 11:27, Rushabh Lath= ia <rushab= h.lathia@gmail.com> wrote:
>
> Hi hackers,
>
> Please find the attached patch, to implement the ORDER BY ALL clause.<= br> > Commit ef38a4d97, implemented GROUP BY ALL clause, and this
> feature follows the same pattern.
>
> ORDER BY ALL is a form of ORDER BY that automatically adds all
> non-junk columns from the SELECT target list to the ORDER BY clause. >
> This implementation supports:
>=C2=A0 =C2=A0- ORDER BY ALL (default ascending order)
>=C2=A0 =C2=A0- ORDER BY ALL ASC
>=C2=A0 =C2=A0- ORDER BY ALL DESC
>=C2=A0 =C2=A0- ORDER BY ALL NULLS FIRST/LAST
>=C2=A0 =C2=A0- ORDER BY ALL ASC/DESC NULLS FIRST/LAST
>
> The syntax works by creating a marker SortBy node with a NULL
> node pointer that carries the sort direction and nulls ordering.
> During query transformation, this marker is detected and expanded
> to order by all non-junk columns in the target list with the
> specified direction.
>
> Implementation details:
> - gram.y: Added ORDER BY ALL grammar with optional ASC/DESC and NULLS<= br> >=C2=A0 =C2=A0in both main sort_clause and PLpgSQL_Expr rules
> - parse_clause.c: Implemented ORDER BY ALL expansion logic that iterat= es
>=C2=A0 =C2=A0over target list columns
> - analyze.c: Updated to pass orderByAll flag through transformation > - parsenodes.h: Added orderByAll boolean to SelectStmt and Query
> - ruleutils.c: Added deparsing support for ORDER BY ALL that preserves=
>=C2=A0 =C2=A0sort direction and NULLS ordering in view definitions, inc= luding proper
>=C2=A0 =C2=A0handling of implicit vs explicit ordering
>
> Please take a look at the attached patch and let me know your thoughts= .
>
> Thanks,
> Rushabh Lathia
> www.EnterpriseDB.com
>

Hi! What about SQL standard compatibility? ef38a4d97 was merged only
after the SQL committee accepted GROUP BY ALL, there was discussion a
few years before [0] which ended up in nothing because of SQL
standard... So I wonder what is perspective of this thread


[0] https://www.postgresql.org/message-id/CAAhFRxjyTO5BHn9y1oOSEp0T= tpTDTTTb7HJBNhTG%2Bi3-hXC0XQ%40mail.gmail.com

Thanks a lot for sharing this.=C2=A0 I was not aware that ORDER BY A= LL is not yet
part of SQL Standards (my bad).=C2=A0
=C2=A0
<= br>
--
Best regards,
Kirill Reshke


--
Rushabh Lathia
--000000000000a8ee1f064dc21586--