In COPY FROM, fail cleanly when unsupported encoding conversion is needed.
authorTom Lane <[email protected]>
Sun, 1 Oct 2023 16:09:26 +0000 (12:09 -0400)
committerTom Lane <[email protected]>
Sun, 1 Oct 2023 16:09:26 +0000 (12:09 -0400)
In recent releases, such cases fail with "cache lookup failed for
function 0" rather than complaining that the conversion function
doesn't exist as prior versions did.  Seems to be a consequence of
sloppy refactoring in commit f82de5c46.  Add the missing error check.

Per report from Pierre Fortin.  Back-patch to v14 where the
oversight crept in.

Discussion: https://postgr.es/m/20230929163739.3bea46e5[email protected]

src/backend/commands/copyfrom.c

index f31cc252002ad3056e0699a9907e6f3c51c137b5..63c4da07814c8c1872bdf60c1e41b65192dc6ca1 100644 (file)
@@ -1334,6 +1334,12 @@ BeginCopyFrom(ParseState *pstate,
        cstate->need_transcoding = true;
        cstate->conversion_proc = FindDefaultConversionProc(cstate->file_encoding,
                                                            GetDatabaseEncoding());
+       if (!OidIsValid(cstate->conversion_proc))
+           ereport(ERROR,
+                   (errcode(ERRCODE_UNDEFINED_FUNCTION),
+                    errmsg("default conversion function for encoding \"%s\" to \"%s\" does not exist",
+                           pg_encoding_to_char(cstate->file_encoding),
+                           pg_encoding_to_char(GetDatabaseEncoding()))));
    }
 
    cstate->copy_src = COPY_FILE;   /* default */