| From: | "Matheus Alcantara" <matheusssilv97(at)gmail(dot)com> |
|---|---|
| To: | <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Show expression of virtual columns in error messages |
| Date: | 2026-02-03 14:06:47 |
| Message-ID: | DG5DV8SED62G.2WFJB46D7WIT8@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
When a constraint violation occurs on a table with virtual generated
columns, the "Failing row contains" error message currently displays the
literal string "virtual" as a placeholder:
CREATE TABLE t (a int, b int, c int GENERATED ALWAYS AS (a * 2) VIRTUAL CHECK (c < 10));
INSERT INTO t VALUES (5, 10);
ERROR: new row for relation "t" violates check constraint "t_c_check"
DETAIL: Failing row contains (5, 10, virtual).
This isn't very helpful for debugging, especially when the user needs to
understand why the check constraint failed or if multiple virtual
generated columns are involved on the original statement.
The attached patch changes this behavior to show the virtual column
expression instead:
ERROR: new row for relation "t" violates check constraint "t_c_check"
DETAIL: Failing row contains (5, 10, a * 2).
An alternative approach would be to compute and display the actual value
of the virtual column (e.g., "10" instead of "a * 2"). However, I chose
to show the expression because:
1. It's simpler to implement (no need to evaluate the expression)
2. It shows the user *how* the value is computed, which may be more
useful for understanding why a constraint failed
3. It avoids potential issues with expression evaluation in error paths
Thoughts?
--
Matheus Alcantara
EDB: https://www.enterprisedb.com
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Show-expression-of-virtual-columns-in-error-messa.patch | text/plain | 12.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | David G. Johnston | 2026-02-03 14:12:23 | Re: Add LIMIT option to COPY FROM |
| Previous Message | Shinya Kato | 2026-02-03 13:49:14 | Add LIMIT option to COPY FROM |