Adjust code to PG14 copy code changes

PG14 splits Copy code into separate code for COPY FROM and COPY TO
since we were only interested in the COPY FROM parts we macro CopyFromState
to CopyState for versions < 14

https://github.com/postgres/postgres/commit/c532d15ddd
This commit is contained in:
Sven Klemm 2021-06-04 12:05:15 +02:00 committed by Sven Klemm
parent 071b391e05
commit 47d9eaca74
4 changed files with 20 additions and 7 deletions

View File

@ -175,6 +175,15 @@ get_vacuum_options(const VacuumStmt *stmt)
(analyze ? VACOPT_ANALYZE : 0);
}
/* PG14 splits Copy code into separate code for COPY FROM and COPY TO
* since we were only interested in the COPY FROM parts we macro CopyFromState
* to CopyState for versions < 14
* https://github.com/postgres/postgres/commit/c532d15ddd
*/
#if PG14_LT
#define CopyFromState CopyState
#endif
/* PG13 added a dstlen parameter to pg_b64_decode and pg_b64_encode */
#if PG13_LT
#define pg_b64_encode_compat(src, srclen, dst, dstlen) pg_b64_encode((src), (srclen), (dst))

View File

@ -36,6 +36,7 @@
#include <utils/rel.h>
#include <utils/rls.h>
#include "compat/compat.h"
#include "hypertable.h"
#include "copy.h"
#include "dimension.h"
@ -56,7 +57,7 @@
*/
static CopyChunkState *
copy_chunk_state_create(Hypertable *ht, Relation rel, CopyFromFunc from_func, CopyState cstate,
copy_chunk_state_create(Hypertable *ht, Relation rel, CopyFromFunc from_func, CopyFromState cstate,
TableScanDesc scandesc)
{
CopyChunkState *ccstate;
@ -272,7 +273,7 @@ copyfrom(CopyChunkState *ccstate, List *range_table, Hypertable *ht, void (*call
/* Set up callback to identify error line number.
*
* It is not necessary to add an entry to the error context stack if we do
* not have a CopyState or callback. In that case, we just use the existing
* not have a CopyFromState or callback. In that case, we just use the existing
* error already on the context stack. */
if (ccstate->cstate && callback)
{
@ -608,7 +609,7 @@ void
timescaledb_DoCopy(const CopyStmt *stmt, const char *queryString, uint64 *processed, Hypertable *ht)
{
CopyChunkState *ccstate;
CopyState cstate;
CopyFromState cstate;
bool pipe = (stmt->filename == NULL);
Relation rel;
List *attnums = NIL;
@ -653,6 +654,9 @@ timescaledb_DoCopy(const CopyStmt *stmt, const char *queryString, uint64 *proces
cstate = BeginCopyFrom(pstate,
rel,
#if PG14_GE
NULL,
#endif
stmt->filename,
stmt->is_program,
NULL,

View File

@ -27,7 +27,7 @@ typedef struct CopyChunkState
EState *estate;
ChunkDispatch *dispatch;
CopyFromFunc next_copy_from;
CopyState cstate;
CopyFromState cstate;
TableScanDesc scandesc;
Node *where_clause;
} CopyChunkState;

View File

@ -631,7 +631,7 @@ remote_copy_get_copycmd(RemoteCopyContext *context)
}
static StringInfo
parse_next_text_row(CopyState cstate, List *attnums, TextCopyContext *ctx)
parse_next_text_row(CopyFromState cstate, List *attnums, TextCopyContext *ctx)
{
StringInfo row_data = makeStringInfo();
int i;
@ -693,7 +693,7 @@ generate_binary_copy_data(Datum *values, bool *nulls, List *attnums, FmgrInfo *o
}
static StringInfo
parse_next_binary_row(CopyState cstate, List *attnums, BinaryCopyContext *ctx)
parse_next_binary_row(CopyFromState cstate, List *attnums, BinaryCopyContext *ctx)
{
if (!NextCopyFrom(cstate, ctx->econtext, ctx->values, ctx->nulls))
return NULL;
@ -702,7 +702,7 @@ parse_next_binary_row(CopyState cstate, List *attnums, BinaryCopyContext *ctx)
}
static bool
read_next_copy_row(RemoteCopyContext *context, CopyState cstate)
read_next_copy_row(RemoteCopyContext *context, CopyFromState cstate)
{
if (context->binary_operation)
context->row_data = parse_next_binary_row(cstate, context->attnums, context->data_context);