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 1vvhzW-00FAC3-0D for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Feb 2026 20:29:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vvhzV-00FHvF-06 for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Feb 2026 20:29:45 +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 1vvhzU-00FHv1-2J for pgsql-hackers@lists.postgresql.org; Thu, 26 Feb 2026 20:29:44 +0000 Received: from mail-dy1-x1332.google.com ([2607:f8b0:4864:20::1332]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vvhzQ-00000001S3T-3HVq for pgsql-hackers@lists.postgresql.org; Thu, 26 Feb 2026 20:29:43 +0000 Received: by mail-dy1-x1332.google.com with SMTP id 5a478bee46e88-2bdbe434b47so2794057eec.1 for ; Thu, 26 Feb 2026 12:29:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772137779; x=1772742579; darn=lists.postgresql.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=vxaiH3eYfK8Xikht5YvmcIdbhnu+ldy3c0ofMZgQPH4=; b=Lkp+qjT3KYEE2Ytxlccp6h+fwsMf5z+bSeOtf5sPFtdLaUU5mLJSmKBz126nKyLkO6 bFELwNZ326O1MxwcV4uGvgUZ+9mMTServKw3aslcweMYfBUSLqmqEynkhumAev645I0p YD/9fLi5ieHiCb1fDchgQsFDOINO5XQG1x+e/ExbpXJfq65zkl54K895qwlhpl+36Ow/ nVaKrD83V60TysTpUoGzPagwbtfggaAShYig6kPErsuKDh8FMBBzOAkgAiUPAJU6iNqe Lt/1JASNzMz/ofbJQasRenQC8oXeprE6+Pl4QpVjYCZ3R6O3cHdzQPtKrew1jp2f3JLf aEOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772137779; x=1772742579; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=vxaiH3eYfK8Xikht5YvmcIdbhnu+ldy3c0ofMZgQPH4=; b=ZeveEdqoJwGiPYWVXkPYg71JdE3MgomyqTf0N4agN16rH9Es2MRRi55tQULW2nn3Zb eX+lgN3hyYG/2o8bJyuaIonzY4C6lNOPfmGqDvm1TBqBZZWU4ar3KOhmCug7YrP1aYvF orFdsrPCAWB9jzii33rENeRIUw8pcpzJgKu0bAjoP3oqUXGE2+7KBldqIGonmbieK6yv mgAV+H+qY2WfPCu4WMUg4tu3KnxzwrV1jATpNVK+p2VW0qNyAGg5FgkCXoD22m9zU5a5 guSjM73SCmeZAlONMvNumLO5CyU1/RnwI/7zJeVbal2JAK9DYg0qsl0FDU8RWXCqrqZA ADhw== X-Gm-Message-State: AOJu0YxEvUfY4zIjvvNUS5vzSKRA1x0jeWsWuAT9hwKZFwGBWpyh8gkN soTy8UaFDteVBLkhHejnUmHWKYlIbsI631LF9gvdWkoG4KC/+cfd0Qc+ X-Gm-Gg: ATEYQzwW02KzcRD++dF+HnbnUJuR/USc1wBn59Y8zQfg33JqT/Bxq9sI8Es5d58tTtR vnNtcY+R/liDmPEkRwIhYSNdS4gXkaANPSrAF2oiq8AuK5ktghkdAvKQyScjeoz5MsjGw8zD0Vs zGxpZZkWVJmdlcwA7UUR9M8GFk+O031TQp37xIppxUE67tc3Kw/TFmcwUOIFTFizyfSOeZzC4TU VZHomq3hZfCQruSEjcFzOfJLvCRGx04VFEAYiewfp8wMKhlx5Dpm1hg+kp5C6cJcn47JZJ7BHCE lGcoe6xXKjammIACxKYzueTIZN56YFJdOtTDY9pGmFY7lxD6CW75p0Fc4fOKzu5b2Uk86jzq/ux 1gXTEg9o3KiF78esqVE2AI2x6NJL/ReLJm10Zs45Iockf9IT5Lt7gT+Qa3xFiKoSui0pcdFSNid AR2xr9M2ayrqEcteRhbNr9lYF/1ZOWs3dJJebk7V50hiGaTA== X-Received: by 2002:a05:7300:a498:b0:2ba:7aed:560d with SMTP id 5a478bee46e88-2bde1d3402amr190754eec.28.1772137778927; Thu, 26 Feb 2026 12:29:38 -0800 (PST) Received: from localhost ([2804:14d:328a:a59c:a4b8:2a46:26e5:b6cc]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2bdd1f23c1csm2505045eec.18.2026.02.26.12.29.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Feb 2026 12:29:38 -0800 (PST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 26 Feb 2026 17:29:34 -0300 Message-Id: Cc: , "Peter Eisentraut" , "Yugo Nagata" Subject: Re: Show expression of virtual columns in error messages From: "Matheus Alcantara" To: "Tom Lane" X-Mailer: aerc 0.21.0 References: <7c18e854-0ddb-4670-b0c4-f2541b5edd91@eisentraut.org> <20260205114521.6fed028d8d3185663f3c4226@sraoss.co.jp> <20260206125414.8f8c5f5735aa34fb05c5cc72@sraoss.co.jp> <2f55b9a4-332f-45c7-9b27-590637a2bb9a@gmail.com> <719803.1772131627@sss.pgh.pa.us> In-Reply-To: <719803.1772131627@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu Feb 26, 2026 at 3:47 PM -03, Tom Lane wrote: > Matheus Alcantara writes: >> Attached rebased v3 due to f80bedd52b1. No additional changes compared= =20 >> to v2. > > I looked at this and frankly I think it's going in the wrong > direction. I agree that showing "virtual" is unhelpful, but > I don't like this approach for a couple of reasons: > > 1. Inserting a column expression could easily make the error > message annoyingly long. > > 2. Adding this much complexity in an error code path doesn't > seem like a good idea. Such paths are typically not well > tested, and if there is any bug lurking, it will result in > an error message quite removed from the user's problem. > > 3. It's making virtual generated columns behave (even more) > differently from stored generated columns. I think the > general plan has been to make them act as alike as possible. > > So what would comport better with the behavior of stored columns > is to show the expression's value. I agree with you that > calculating that in the error path is a no-go, but haven't we > computed it earlier? Or could we do so, if there are constraints > to be checked? Thanks for the feedback. After investigating the code a bit, I found that IIUC virtual column values are actually never computed and stored separately, they're computed by expanding the expression wherever the column is referenced. According to my understanding, here's how it works during constraint checking in ExecRelCheck(): 1. The constraint expression (e.g., c > 10) is loaded from the catalog 2. Virtual column references are expanded via expand_generated_columns_in_expr(), transforming it to (a + b) > 10=20 3. ExecCheck() evaluates the entire expanded expression, reading base column values (a, b) directly from the slot and returns the if the check was true or false. The virtual column value (a + b) is computed as an intermediate result during expression evaluation of a check constraint but is never stored anywhere accessible. So, if all of this make sense and it's correct it seems to me that we indeed need to compute the virtual expression value on error path to show on error message although it would not be desirable, or I'm missing something? -- Matheus Alcantara EDB: https://www.enterprisedb.com