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 1w4wj2-002jAD-1Q for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 08:02:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w4wj0-005FpJ-20 for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 08:02:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w4wj0-005Foy-0x for pgsql-hackers@lists.postgresql.org; Tue, 24 Mar 2026 08:02:54 +0000 Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w4wix-00000000qFd-3QN1 for pgsql-hackers@postgresql.org; Tue, 24 Mar 2026 08:02:54 +0000 Received: by mail-qt1-x831.google.com with SMTP id d75a77b69052e-50912a097b0so5585451cf.1 for ; Tue, 24 Mar 2026 01:02:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774339370; cv=none; d=google.com; s=arc-20240605; b=XZBjJdAHeFu/YIx2wDM5spx7ZaJ6BaqpfRzbxh9c40tcze0OkzOEkUTbbyImV8R5PI nzY50NjJZAqPlAoRSxQ5XKpcP1CSnP7bgG5MfkgXkVikJ0fhSiOcgSWbexyFx387Hzsy PaepKa5W+FVp1RVwi6K5e/766xoRSMXzeiLrbt278DcZIeZCi5qWpiCf0C/6/dOnma/j g8092siJaRnt2JQMy9m4BvSKVcHo9yRoBxFtVoUaEwklkfRLNdVLv1H2Bl9+P2vHCdYH SgRVHm+AtJ0hhUipwABiGGuJhSosYBTyUnrR5jeoDUItRB7h4fUtUSXN6+HOBLteeIzA m9fQ== 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=o+Xs+QHbl0T80a1yHYPRmQ8+aTqwvKcrlrOcKgSsv0o=; fh=iGa7mxCNME6zgEKcEj4rpG/UVCIXnt+HwTEa5afgXvE=; b=StwwMBgCLaMWIoTQmSsL/N8TWxtDeSeSJzDjrmEUHnGfHXIqYBZDL0T6LeeO9gYYMb qiKbMyO79yZuJM9HU6arSXMStmsJmttCeHxkU5eyr5R8fti+N+uqiAf0n1uapTi7/TrA ITGR938F7bi93mmtn4mkfmVrfz5G1e4lyGNBnI02z+Rn1V8TvSvksawgBnFJ06Dla8gg ArZMqbpEKdb4tQ2h03SEGPsxX/KU5trfQ5QH+EVaQ60o25mo+Ign61UyLZVTU5JiUFlX j/x6R/r3CzuTfTNRD8SXfqcUx4dHQGH/GxVAcGl/FjkiE6y3bcJlluVMvp1q/AiCIYaP IioQ==; 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=1774339370; x=1774944170; 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=o+Xs+QHbl0T80a1yHYPRmQ8+aTqwvKcrlrOcKgSsv0o=; b=FlRjIlhYg1v8UOqTzAqU9uVmgEr5NnTXIi8iD2AhG9dAH5gAsljH6UiiAC/sWMdToP 2Ud2LXE1DIH0DYUkTln2EKF4HQkZdtgKn+vmghTeErtT/TUVSFd06hPLkVOPQJ7mCV4f F3a3gyJnFJ+DSxs5rd+7WBahFs4X/5LxksD8Fas2T58Lwof33T/HOFTYA7CBjhZBbns8 pZ1W3hjrUZrega0+gkGODJJx5/sbspq/kOaonBs82WNbgrNbbHKilaXPOVgGf1pnI9hQ ZS6MShlbvYBteKIMkjmHqZH96o/Q7m0FMg3dyDmudT65giQubC4mdnAX2vGAHzs1zqSF nM0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774339370; x=1774944170; 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=o+Xs+QHbl0T80a1yHYPRmQ8+aTqwvKcrlrOcKgSsv0o=; b=GlAq3my12wI5zBaqz7RbuiEr4+cqkQ6ZYjkdvrNpTum4DN7beYs/bUNAFXCTVLI32n zdf4xO6RxwrOEdeZXeJRrcH+/pVOJUdzHXBKuTdiMZ4QtSCFvsbf1QnOvKZXeZ/Oq++r OOJaglhc+iheNRxM1jrIsQkjJB+4KIO9TGJ2DXuFc0TUE1PGWpgVa8UFrxtxRt7qTGz/ +dLo64ATZDNpN2BF7+jlKmfx/ptW1R7UBQBngq4tKPwhmcokl/XE4ZvtiSshhHHp7jmd 5o+nfW2IdlkQvhKWsdKkfCab6mTHKybmnAipWrpwhZj5nAWMcCnMiKO5Vo9lhhNevaWh t0Ag== X-Gm-Message-State: AOJu0YwejKM+mycPSD4JwyPEhSbYwVSmGx1UDri/AnB/hpHPmzDBkpL6 TyIm5yo0Gpe4cBI5d5YoV1lKMBAUi9JetppLekzi6oMIQT4Vo/uemWBsOK+exr9OK0mvyt9M1KC 5cbBG0FEv8Hg9JodYAdSgi9b7dph8oKU= X-Gm-Gg: ATEYQzzVlAZwwuK5gQJpy3VLdkqdH+av9Bdn+jT5cqdIBNrTSiGkqVI71fDOUUikiJh qTqU3ZkvDQEZL3jOLsXRCgyUtsJhReezWQZQtbHwcRBpk6uUwJ0WKqc8SlQU3e8wvQLkShg9opG r4Zs/8DQN3krC23y4mtKcAaGQU4xz+Ls8TMd9Rl4pqN+KN5aRKWqoqqgSYD4VG6MLchbQGTWQTi WG7Wsc4ZjdaXhneJt8kRtzK/K3TyjovozvTOT1mip8sFsnyGLj7IK4I2I4fhapqXVWmQyzqN5Gp yEG97a4ptp6wEgUn396Ti4XAirQe63k68AoR+AMzOaPK7tMS1mD7DiwT4TNBbzQreNXQ6gxCQlQ 1nJ0m7rD8fhUR4hO3 X-Received: by 2002:a05:622a:2609:b0:50b:51a0:f745 with SMTP id d75a77b69052e-50b51a0fce0mr133989441cf.6.1774339370060; Tue, 24 Mar 2026 01:02:50 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Kirill Reshke Date: Tue, 24 Mar 2026 13:02:38 +0500 X-Gm-Features: AaiRm53wq_zDWHNvI_4FwoHTuBj24L7O61EtlB-pbe1weEKVCbZjm42mpTVKtLQ Message-ID: Subject: Re: ORDER BY ALL To: Rushabh Lathia Cc: PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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 iterates > 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 proper > 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/CAAhFRxjyTO5BHn9y1oOSEp0TtpTDTTTb7HJBNhTG%2Bi3-hXC0XQ%40mail.gmail.com -- Best regards, Kirill Reshke