postgresql/src/backend
Tom Lane 97d6716723 Fix failure for generated column with a not-null domain constraint.
If a GENERATED column is declared to have a domain data type where
the domain's constraints disallow null values, INSERT commands failed
because we built a targetlist that included coercing a null constant
to the domain's type.  The failure occurred even when the generated
value would have been perfectly OK.  This is adjacent to the issues
fixed in 0da39aa76, but we didn't notice for lack of testing a domain
with such a constraint.

We aren't going to use the result of the targetlist entry for the
generated column --- ExecComputeStoredGenerated will overwrite it.
So it's not really necessary that it have the exact datatype of
the generated column.  This patch fixes the problem by changing
the targetlist entry to be a null Const of the domain's base type,
which should be sufficiently legal.  (We do have to tweak
ExecCheckPlanOutput to accept the situation, though.)

This has been broken since we implemented generated columns.
However, this patch only applies easily as far back as v14, partly
because I (tgl) only carried 0da39aa76 back that far, but mostly
because v14 significantly refactored the handling of INSERT/UPDATE
targetlists.  Given the lack of field complaints and the short
remaining support lifetime of v13, I judge the cost-benefit ratio
not good for devising a version that would work in v13.

Reported-by: jian he <jian.universality@gmail.com>
Author: jian he <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CACJufxG59tip2+9h=rEv-ykOFjt0cbsPVchhi0RTij8bABBA0Q@mail.gmail.com
Backpatch-through: 14
2025-04-15 12:08:34 -04:00
..
access Fix GIN's shimTriConsistentFn to not corrupt its input. 2025-04-12 12:27:46 -04:00
backup Replace pgwin32_is_junction() with lstat(). 2024-11-08 09:29:40 +10:30
bootstrap Process session_preload_libraries within InitPostgres's transaction. 2022-07-25 10:27:43 -04:00
catalog Repair misbehavior with duplicate entries in FK SET column lists. 2025-04-04 20:11:48 -04:00
commands Repair misbehavior with duplicate entries in FK SET column lists. 2025-04-04 20:11:48 -04:00
executor Fix failure for generated column with a not-null domain constraint. 2025-04-15 12:08:34 -04:00
foreign Restrict accesses to non-system views and foreign tables during pg_dump. 2024-08-05 06:05:25 -07:00
jit Fix NULLIF()'s handling of read-write expanded objects. 2024-11-25 18:09:10 -05:00
lib Accommodate very large dshash tables. 2024-12-17 15:24:45 -06:00
libpq Fix regression in TLS session ticket disabling 2024-08-19 12:55:11 +02:00
main Fix elog(FATAL) before PostmasterMain() or just after fork(). 2024-12-10 13:52:02 -08:00
nodes Build whole-row Vars the same way during parsing and planning. 2025-03-12 11:47:19 -04:00
optimizer Fix failure for generated column with a not-null domain constraint. 2025-04-15 12:08:34 -04:00
parser Fix parse_cte.c's failure to examine sub-WITHs in DML statements. 2025-04-05 15:01:33 -04:00
partitioning Fix creation of partition descriptor during concurrent detach+drop 2024-08-12 18:17:56 -04:00
po Translation updates 2025-02-17 17:51:30 +01:00
port Close socket in case of errors in setting non-blocking 2024-01-17 11:24:11 +01:00
postmaster Don't ask for bug reports about pthread_is_threaded_np() != 0. 2025-01-23 14:23:34 -05:00
regex Fix recently-exposed portability issue in regex optimization. 2024-11-17 14:14:06 -05:00
replication Fix race with synchronous_standby_names at startup 2025-04-11 10:02:18 +09:00
rewrite Repair commits 317aba70e et al for -DWRITE_READ_PARSE_PLAN_TREES. 2025-03-13 12:13:07 -04:00
snowball Avoid null pointer dereference crash after OOM in Snowball stemmers. 2025-02-18 21:23:59 -05:00
statistics Fix incorrectly reported stats kind in "can't happen" ERROR 2024-03-05 16:18:19 +13:00
storage doc: Correct description of values used in FSM for indexes 2025-03-27 10:20:48 +09:00
tcop Repair commits 317aba70e et al for -DWRITE_READ_PARSE_PLAN_TREES. 2025-03-13 12:13:07 -04:00
tsearch Clear errno before calling strtol() in spell.c. 2025-03-08 11:24:52 -05:00
utils Remove unnecessary type violation in tsvectorrecv(). 2025-04-02 16:18:03 -04:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
Makefile Move basebackup code to new directory src/backend/backup 2022-08-10 14:03:09 -04:00
nls.mk Translation updates 2023-11-06 13:16:22 +01:00