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 1oj3yu-0006cP-6T for pgsql-docs@arkaria.postgresql.org; Thu, 13 Oct 2022 19:35:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oj3yt-0006Cb-00 for pgsql-docs@arkaria.postgresql.org; Thu, 13 Oct 2022 19:34:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oj3ys-0006CL-P5 for pgsql-docs@lists.postgresql.org; Thu, 13 Oct 2022 19:34:58 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oj3yl-0000ZV-2T for pgsql-docs@lists.postgresql.org; Thu, 13 Oct 2022 19:34:57 +0000 Received: from bruce by momjian.us with local (Exim 4.94.2) (envelope-from ) id 1oj3yk-00AOCh-9K; Thu, 13 Oct 2022 15:34:50 -0400 Date: Thu, 13 Oct 2022 15:34:50 -0400 From: Bruce Momjian To: matthias01123@gmail.com, pgsql-docs@lists.postgresql.org Subject: Re: COALESCE could use some better examples Message-ID: References: <166567130399.591812.10092275852150047596@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <166567130399.591812.10092275852150047596@wrigleys.postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Oct 13, 2022 at 02:28:23PM +0000, PG Doc comments form wrote: > The following documentation comment has been logged on the website: > > Page: https://www.postgresql.org/docs/15/functions-conditional.html > Description: > > Regarding: > https://www.postgresql.org/docs/current/functions-conditional.html > > I ran into a situation where COALESCE was used like this > > ``` > SELECT * FROM table WHERE COALESCE(col_1, col_2, col_3) >= 5 > ``` > > and didn't understand how it worked, and the examples don't really help > because they only use COALESCE like > > ``` > SELECT COALESCE(..) > ``` > > I asked and answered a question on stackoverflow with a pretty good example > of this, you could consider adding to your page. > > Thank you :)) > > Stackoverflow question link: > https://stackoverflow.com/questions/74057319/coalesce-in-postgresql-conditional-displaying-seemingly-undocumented-behavior I read the Stackoverflow thread and it seems you thought a column name in the function in a WHERE clause should span all the rows looking for the first non-NULL row, and only if they are all NULL, go to th next parameter. All WHERE functions are row-based so I don't see how to actually improve our doc text without making it more confusing. Sorry. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Indecision is a decision. Inaction is an action. Mark Batterson