From 276393f53efbf08f72190221e9c1ef2a28e7fc66 Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Sun, 1 Oct 2023 10:18:41 -0400 Subject: Only evaluate default values as required when doing COPY FROM Commit 9f8377f7a2 was a little too eager in fetching default values. Normally this would not matter, but if the default value is not valid for the type (e.g. a varchar that's too long) it caused an unnecessary error. Complaint and fix from Laurenz Albe Backpatch to release 16. Discussion: https://postgr.es/m/75a7b7483aeb331aa017328d606d568fc715b90d.camel@cybertec.at --- src/backend/commands/copyfrom.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/backend/commands/copyfrom.c') diff --git a/src/backend/commands/copyfrom.c b/src/backend/commands/copyfrom.c index 2d1567d0e42..cf0fc9d794d 100644 --- a/src/backend/commands/copyfrom.c +++ b/src/backend/commands/copyfrom.c @@ -1571,7 +1571,14 @@ BeginCopyFrom(ParseState *pstate, /* Get default info if available */ defexprs[attnum - 1] = NULL; - if (!att->attgenerated) + /* + * We only need the default values for columns that do not appear in + * the column list, unless the DEFAULT option was given. We never need + * default values for generated columns. + */ + if ((cstate->opts.default_print != NULL || + !list_member_int(cstate->attnumlist, attnum)) && + !att->attgenerated) { Expr *defexpr = (Expr *) build_column_default(cstate->rel, attnum); -- cgit v1.2.3