copy_encoding.v3.patch
application/octet-stream
Filename: copy_encoding.v3.patch
Type: application/octet-stream
Part: 0
Message:
Re: Add ENCODING option to COPY
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
Series: patch v3
| File | + | − |
|---|---|---|
| src/backend/commands/copy.c | 18 | 4 |
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 93fb2cf..6ea9372 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -1370,8 +1370,13 @@ CopyTo(CopyState cstate)
/* We use fe_msgbuf as a per-row buffer regardless of copy_dest */
cstate->fe_msgbuf = makeStringInfo();
- /* Setup encoding conversion proc */
- if (cstate->need_transcoding)
+ /*
+ * We don't need conversion procedure when the encodings match
+ * between target and server, but need_transcoding indicates
+ * we need verify encoding still.
+ */
+ if (cstate->need_transcoding &&
+ cstate->target_encoding != GetDatabaseEncoding())
{
Oid funcoid;
@@ -1380,6 +1385,8 @@ CopyTo(CopyState cstate)
cstate->conv_proc = (FmgrInfo *) palloc(sizeof(FmgrInfo));
fmgr_info(funcoid, cstate->conv_proc);
}
+ else
+ cstate->conv_proc = NULL;
/* Get info about the columns we need to process. */
cstate->out_functions = (FmgrInfo *) palloc(num_phys_attrs * sizeof(FmgrInfo));
@@ -1989,8 +1996,13 @@ CopyFrom(CopyState cstate)
cstate->cur_attname = NULL;
cstate->cur_attval = NULL;
- /* Setup encoding conversion proc */
- if (cstate->need_transcoding)
+ /*
+ * We don't need conversion procedure when the encodings match
+ * between target and server, but need_transcoding indicates
+ * we need verify encoding still.
+ */
+ if (cstate->need_transcoding &&
+ cstate->target_encoding != GetDatabaseEncoding())
{
Oid funcoid;
@@ -1999,6 +2011,8 @@ CopyFrom(CopyState cstate)
cstate->conv_proc = (FmgrInfo *) palloc(sizeof(FmgrInfo));
fmgr_info(funcoid, cstate->conv_proc);
}
+ else
+ cstate->conv_proc = NULL;
bistate = GetBulkInsertState();