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.94.2) (envelope-from ) id 1udrnb-001clS-C6 for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Jul 2025 14:47:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1udrna-001TYd-7F for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Jul 2025 14:47:26 +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.94.2) (envelope-from ) id 1udrnZ-001TYV-U9 for pgsql-hackers@lists.postgresql.org; Mon, 21 Jul 2025 14:47:26 +0000 Received: from mail-ot1-x32c.google.com ([2607:f8b0:4864:20::32c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1udrnY-0002Mc-17 for pgsql-hackers@postgresql.org; Mon, 21 Jul 2025 14:47:25 +0000 Received: by mail-ot1-x32c.google.com with SMTP id 46e09a7af769-73e810dc245so2035344a34.1 for ; Mon, 21 Jul 2025 07:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753109243; x=1753714043; darn=postgresql.org; h=in-reply-to:references:subject:cc:to:from:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=rdC7Phpb8NHtDdTnIfoy8zJUY8d9+fJ6NmDiqj7K0Xs=; b=fjJvm33Jr9DXFAsbD30ES+nZszANQE26IaOJ/N1NnI5l6s9avm6WkyNEsmz8YffPea FZJd4y+oFthMd1R+GSd/vnsq0UnafTez1W3gADZzTcQWPeYoXJLgm6Xh5pW2nzJRW1Q6 NFzk1BeGKKWRFcRtGcA4kOITDepHAq2/cABFU9qSx68xX8p6Qkd1NsysjZKAXmRW+0Gl QeDAucxH2o40zzVt+UoF+coAu9A6voOn6K3oRZBL7603zjEla+oScNzgr61yTGQSnkvN tDADI/ik3ioKq6XKalD8IrsYd+5xDXndCkfIVWH8oXl5J4nTQ9+rXXhe/k2AU9RH2c5L 0rgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753109243; x=1753714043; h=in-reply-to:references:subject:cc:to:from:message-id:date :content-transfer-encoding:mime-version:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=rdC7Phpb8NHtDdTnIfoy8zJUY8d9+fJ6NmDiqj7K0Xs=; b=SJGyjqErShHuiAaYEKop0iya3ejd3CkQb1jlJ6JS8u1B0Qz88CH9wpGVZFRByJlTaT FHBvWyJ1HESPr6HuSrpqy3ncwR8BwdB2BhonQStZKTtccp6XQ7qTcx/NU9/FvaFIiEcM IDk7NcHXT5ZgMr14zQD2T9sBNhl8KVT/+DqvY0nOMlBwK7m8ClcTm8hzjXa82Ri0zPJB tlOWPu0QAF3AcOkHRoIqE3I3jwnLmL93cV39M2nGnlFLShfqzPbw6wq7+VNPqoQE9das gcBWQMiVCT/UCpm4mnO5tHJm28A9YWGLuOMgvR7YaemWPCzuWbctyoK/EPZIMt/O5whV oFoQ== X-Gm-Message-State: AOJu0YyDufOHY4EYx0yqz4EI8SEcIY6FlA1rbn/Fftb9pbyUkMr13dgQ DCwnQftrWDT5pi23MiAK3J7wiwcoAFyNirLubRerLn1wMGOIWprrbVWR X-Gm-Gg: ASbGncu66AaashP9xmO6SNiK0VfLMB6qzKz9U1Ozho3W0ceOeMpaEml3lreWdeYunSc SC+AvHTJUmrhQeezgWGTvfY846xpExVBZ9wGrOG0kGlPaoV771iqSfOaPIe/Sej/SwgfgGIcmaA e6w5qkv4WXdXGaMDnS3Pc397rWhACU2iIBHciU+iVXfEj1yJgHWHjTZ85qlId+Dh7qP88Pn6Xjy cmDz2ZaCT01H9IHDcM3qAj50cdyY+CGnHaZBwjcqrnGm7Z2bLidgEO25rKiAZl/9K1kQvnI6gPS LAxMjWrw6UPcyf/BUYwB9YNbdJtD2VnrN/bt8OgEGHqOqho7IUd5DI0WriwwKyZmGiA4WYYTeBG 1s0vrGMKDEscw5OYrmiIP8cYpvcGE1eUdyZDq1141Qh8W2w== X-Google-Smtp-Source: AGHT+IHWyYHfGE48ldcuoDhYTHNqcWJPYfzlLX/WNpS1Y5tIyy3ilp+/XRe92mE6VFTYDlgr6Pn/Sg== X-Received: by 2002:a05:6808:198c:b0:41c:4912:1d7a with SMTP id 5614622812f47-41e468a7a26mr8850087b6e.24.1753109243123; Mon, 21 Jul 2025 07:47:23 -0700 (PDT) Received: from localhost ([2804:14d:328a:a59c:943d:28c4:fafd:aa97]) by smtp.gmail.com with ESMTPSA id 5614622812f47-41fd1ca5832sm2284949b6e.17.2025.07.21.07.47.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Jul 2025 07:47:21 -0700 (PDT) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 21 Jul 2025 11:47:19 -0300 Message-Id: From: "Matheus Alcantara" To: "Isaac Morland" , "Mike Artz" Cc: "Pg Hackers" , "Peter Eisentraut" Subject: Re: Proposal: QUALIFY clause X-Mailer: aerc 0.20.1 References: In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon Jul 21, 2025 at 11:29 AM -03, Isaac Morland wrote: > Is this different from using the window functions in a subquery and then > applying a WHERE clause on the outer query? > > SELECT =E2=80=A6 FROM (SELECT =E2=80=A6 [including window functions] FROM= =E2=80=A6) WHERE [stuff > that would be in QUALIFY] > > I'll be honest, I'm skeptical that we need another keyword that basically > means =E2=80=9CWHERE, but applied at a different point in the query proce= ssing=E2=80=9D. > I'm not even convinced that HAVING was a good idea (although obviously I > would not propose removal). >=20 Thanks for sharing your thoughts! You're right =E2=80=94 semantically, using QUALIFY is equivalent to wrappin= g the query in a subquery and applying a WHERE clause to the result. The main motivation here is to provide a more ergonomic and readable syntax. While I understand the hesitation around introducing another keyword that effectively acts like WHERE at a different stage, I believe QUALIFY improves clarity in many use cases, by avoiding the boilerplate and visual noise of nested subqueries making it easier to write and reason about. -- Matheus Alcantara