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 1sOw1x-0023cv-ER for pgsql-docs@arkaria.postgresql.org; Wed, 03 Jul 2024 09:12:01 +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 1sOw1t-007BRQ-Rn for pgsql-docs@arkaria.postgresql.org; Wed, 03 Jul 2024 09:11:58 +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 1sOw1t-007BRH-G7 for pgsql-docs@lists.postgresql.org; Wed, 03 Jul 2024 09:11:58 +0000 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sOw1r-000B1M-9W for pgsql-docs@lists.postgresql.org; Wed, 03 Jul 2024 09:11:56 +0000 Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-584ee8da49aso766058a12.0 for ; Wed, 03 Jul 2024 02:11:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20230601.gappssmtp.com; s=20230601; t=1719997914; x=1720602714; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:autocrypt :references:in-reply-to:date:to:from:subject:message-id:from:to:cc :subject:date:message-id:reply-to; bh=geN+bb4xekuTcswqgXFpkZo293BYE8NsQpgbzN93wu4=; b=KesGgheAvnQB9YhPpd7bl74il4Cs/Ux1g8+x1fGGfk80BbomqJQr3KR3D9FRaVB42l MWDboGHAbrG1GjzYRG1JrJ9Wl9mZwF0roDknn+MpiATPg8XyEM7vbcSRh9dhHUqWaR7J 3xL47mUVk1kWuXQqwje0kV+liRTuQ1a6KBPBaOOybCWH3EVRZ6cq93RBT3jg7u4DPVdn Ih28ZIDPRSQSQ6URuPbQYpRefra5noOw8WZnZDlMVWJrSefBhuqgEwqBeQmPlRcxu+Fb 6YeV+eysw1kf5V3T7MRQjunk8S9s/rvXk8JbFHoUwWn5/L9WN6EMl5iP6BYsrIo3n4Yj QlTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719997914; x=1720602714; h=mime-version:user-agent:content-transfer-encoding:autocrypt :references:in-reply-to:date:to:from:subject:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=geN+bb4xekuTcswqgXFpkZo293BYE8NsQpgbzN93wu4=; b=c2+ew/yvNdt4Hj6Ct+e1cdlGnSMjqQ978wh5AQc7pEf9dC95yuawU/0kBsTMcmgyJw ZqmQap/rfHr1vx6IPpk2J6PXyoy960+E2/XbxRih388f+y8j3kYX6HG+cTG30PHheZ// AnGfIhm0KW0SqBOdEUQWCr3CnNsgj3LkJrL6yl87WApdaUuOjYDknRf7lYw3pWI9j+0k HOwZTctGiQan3wF7GEMd8yyKthwNA6JJcg7ryqTH/cSFzSB1cx2ANvwOhQYJRA6PaQ2x Z0kGqc3j5eqhQkwNyDWROh5B852U/J/oOGy/bSD5mzL1V6R7KxYmG8sluiSVGNdJjS3x 7x+Q== X-Forwarded-Encrypted: i=1; AJvYcCXOH9bbN8jZu1vjNb/6mEKwMNEk6Qv59foCGoeGbRzaGmJX/Q7wGPdGw0AlntxInNIM9a5wxCvU22DRhX9x1WyM/XZyady8DlNh8ZTjfLJo X-Gm-Message-State: AOJu0YyrYFYAKriojPfPIQcRrwZTPS0g2bbBHy5dMmeLJ9uEXMWb4suB 9kU6jsO35Z77XgT3aMPDVBPa5YcEWmeCCl0TC65V/qaCmPcreFcJgjxVW09U6jc= X-Google-Smtp-Source: AGHT+IFyWNSE7anzKRbZx3Aizao4q054yWXPsmnjXsOA1OuC5aOlAcdZB5kFyzZRlTUzr5TH1qFu1A== X-Received: by 2002:a05:6402:40c5:b0:586:178f:aaa4 with SMTP id 4fb4d7f45d1cf-58ce5169885mr929125a12.9.1719997913086; Wed, 03 Jul 2024 02:11:53 -0700 (PDT) Received: from localhost.localdomain ([88.116.133.170]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5861324ff85sm6809185a12.29.2024.07.03.02.11.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jul 2024 02:11:52 -0700 (PDT) Message-ID: <0c98e0da0df5780f05e3eb598bb84955450a74f8.camel@cybertec.at> Subject: Re: COALESCE documentation From: Laurenz Albe To: Peter Eisentraut , =?UTF-8?Q?Navr=C3=A1til=2C_Ond=C5=99ej?= , pgsql-docs@lists.postgresql.org Date: Wed, 03 Jul 2024 11:11:51 +0200 In-Reply-To: <62f888dc-1ee5-48cf-b76c-6a75dcfa8b10@eisentraut.org> References: <62f888dc-1ee5-48cf-b76c-6a75dcfa8b10@eisentraut.org> Autocrypt: addr=laurenz.albe@cybertec.at; prefer-encrypt=mutual; keydata=mQINBGGDwAQBEADgbWy5cKXQld3N2mF+DFyiNFbi2oBl2T+XgxpPF8wTRw2D/u4bBKXP0SYSE/lA86jIVNWWU0gf1KODIkVvgJm2w4vH2VBV1b7ddVViGl1Iu+9zaRnv9wulhnH42KefepXnoean6UT1EzLM0opF/Ik0j+40TxdRtobkBprkQUyHDXWlHc2ffPs3SipyFEP9AVLf7ejRC46CXWDnsqjOBSMEW8Z4HiK/8RrPZBsKLts8dJxKF4pygOdJb0CWk8k/X1jbcfdxo+zOLjOMvJcSJ2pFdJmQHU+JufB3rePziqQ2S9Ur6sccr9XnTC1GVBWN4Lf5VHq+vf+bFJjVwg+2hrySZnAVfcOrxoqFLErr7ug1zN2nM1kcpgA4VWn4gxlJtYNYYq+9WxX5dtvnNANlG3ZCrRKQzl8lxtzo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4SKRuEm54lNhJz//ar86Or5BErzNpM6TL7lk44QS06hwsMrEdKIy8J/SYJPjfzR8tIUnKscclVpOgjKaBqC+0iFiVaRqAgfOlIEiezX6kMh5Q2FIUfqs46qWhhXjRrdKOEoStYAaikdLu5ZXr7vfb0ZaDh+ZwTQtbSMFolyOkecwI81MCdbMfT/1TqIGTOdAj5as9fAakk0jb2pXgUYQ8X1DVTR8ahSDVEaw9VTmWiSvTxvguVJ1Mb7gG4Gmh6aviDTJhfXtH4rPUNXhDLqrTH8JkJjyKROOMakIF68Hjse5vUfUxreBEOtb5r1Coa2Fe7ncJayaSE7ryrDbFqpZ 36UMAx4ulWMyqJajLNGY0DdG8qIsR5nxRhrnK/mrCidZ8F9/D3bWAl4rjtHlsztN59 +AnW5l0HsQcY9ntFL/zEBOaonjdJf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.4 (3.50.4-1.fc39) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 2024-07-03 at 11:00 +0200, Peter Eisentraut wrote: > On 02.07.24 12:45, Navr=C3=A1til, Ond=C5=99ej wrote: > > as per documentation=20 > > > > > The |COALESCE|=C2=A0function returns the first of its arguments that= is=20 > > not null. Null is returned only if all arguments are null. > >=20 > > This is not exactly true. In fact: > > The |COALESCE|=C2=A0function returns the first of its arguments that *i= s=20 > > distinct* *from *null. Null is returned only if all arguments *are not= =20 > > distinct from* null. > >=20 > > See my stack overflow question here=20 > > . > >=20 > > Long story short > >=20 > > > select coalesce((null, null), (10, 20)) as magic; | > >=20 > > returns > >=20 > > > magic ------- (,) (1 row)| > >=20 > > However, this is true: > >=20 > > > select (null, null) is null;| >=20 > I think this is actually a bug in the implementation, not in the=20 > documentation. That is, the implementation should behave like the=20 > documentation suggests. You are right. I find this in the standard: COALESCE (V1, V2) is equivalent to the following : CASE WHEN V1 IS NOT NULL THEN V1 ELSE V2 END That would mean that coalesce(ROW(1,NULL), ROW(2,1)) should return the second argument. Blech. I am worried about the compatibility pain such a bugfix would cause... Yours, Laurenz Albe