From: Andrew Dunstan Date: Wed, 15 Mar 2023 21:16:57 +0000 (-0400) Subject: Don't try to read default for a non-existent attribute X-Git-Url: http://git.postgresql.org/gitweb/-?a=commitdiff_plain;h=b85e91023bf3fd5b4dbd35dc3eddbf0dc291c8ad;p=users%2Frhaas%2Fpostgres.git Don't try to read default for a non-existent attribute Oversight in commit 9f8377f7a2 for COPY .. DEFAULT per report from Alexander Lakhin --- diff --git a/src/backend/commands/copyfromparse.c b/src/backend/commands/copyfromparse.c index c346486cd3..3853902a16 100644 --- a/src/backend/commands/copyfromparse.c +++ b/src/backend/commands/copyfromparse.c @@ -1683,7 +1683,8 @@ CopyReadAttributesText(CopyFromState cstate) strncmp(start_ptr, cstate->opts.null_print, input_len) == 0) cstate->raw_fields[fieldno] = NULL; /* Check whether raw input matched default marker */ - else if (cstate->opts.default_print && + else if (fieldno < list_length(cstate->attnumlist) && + cstate->opts.default_print && input_len == cstate->opts.default_print_len && strncmp(start_ptr, cstate->opts.default_print, input_len) == 0) { @@ -1897,7 +1898,8 @@ endfield: strncmp(start_ptr, cstate->opts.null_print, input_len) == 0) cstate->raw_fields[fieldno] = NULL; /* Check whether raw input matched default marker */ - else if (cstate->opts.default_print && + else if (fieldno < list_length(cstate->attnumlist) && + cstate->opts.default_print && input_len == cstate->opts.default_print_len && strncmp(start_ptr, cstate->opts.default_print, input_len) == 0) {