8000 Escape column names while transforming for wal2json plugin. by shubhamdhama · Pull Request #663 · dimitri/pgcopydb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Escape column names while transforming for wal2json plugin. #663

8000 New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/bin/pgcopydb/ld_wal2json.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ static bool SetMessageRelation(JSON_Object *jsobj,
PGSQL *pgsql);
static bool SetColumnNamesAndValues(LogicalMessageTuple *tuple,
const char *message,
JSON_Array *jscols);
JSON_Array *jscols,
PGSQL *pgsql);


/*
Expand Down Expand Up @@ -126,7 +127,9 @@ parseWal2jsonMessage(StreamContext *privateContext,

LogicalMessageRelation table = { 0 };

if (!SetMessageRelation(jsobj, &table, privateContext->transformPGSQL))
PGSQL *pgsql = privateContext->transformPGSQL;

if (!SetMessageRelation(jsobj, &table, pgsql))
{
log_error("Failed to parse truncated message missing "
"schema or table property: %s",
Expand Down Expand Up @@ -170,7 +173,7 @@ parseWal2jsonMessage(StreamContext *privateContext,

LogicalMessageTuple *tuple = &(stmt->stmt.insert.new.array[0]);

if (!SetColumnNamesAndValues(tuple, message, jscols))
if (!SetColumnNamesAndValues(tuple, message, jscols, pgsql))
{
log_error("Failed to parse INSERT columns for logical "
"message %s",
Expand Down Expand Up @@ -205,7 +208,7 @@ parseWal2jsonMessage(StreamContext *privateContext,
JSON_Array *jsids =
json_object_dotget_array(jsobj, "message.identity");

if (!SetColumnNamesAndValues(old, message, jsids))
if (!SetColumnNamesAndValues(old, message, jsids, pgsql))
{
log_error("Failed to parse UPDATE identity (old) for logical "
"message %s",
Expand All @@ -217,7 +220,7 @@ parseWal2jsonMessage(StreamContext *privateContext,
JSON_Array *jscols =
json_object_dotget_array(jsobj, "message.columns");

if (!SetColumnNamesAndValues(new, message, jscols))
if (!SetColumnNamesAndValues(new, message, jscols, pgsql))
{
log_error("Failed to parse UPDATE columns (new) for logical "
"message %s",
Expand Down Expand Up @@ -246,7 +249,7 @@ parseWal2jsonMessage(StreamContext *privateContext,
JSON_Array *jsids =
json_object_dotget_array(jsobj, "message.identity");

if (!SetColumnNamesAndValues(old, message, jsids))
if (!SetColumnNamesAndValues(old, message, jsids, pgsql))
{
log_error("Failed to parse DELETE identity (old) for logical "
"message %s",
Expand Down Expand Up @@ -317,7 +320,8 @@ SetMessageRelation(JSON_Object *jsobj,
static bool
SetColumnNamesAndValues(LogicalMessageTuple *tuple,
const char *message,
JSON_Array *jscols)
JSON_Array *jscols,
PGSQL *pgsql)
{
int count = json_array_get_count(jscols);

Expand Down Expand Up @@ -353,7 +357,7 @@ SetColumnNamesAndValues(LogicalMessageTuple *tuple,
return false;
}

tuple->columns[i] = strndup(colname, PG_NAMEDATALEN);
tuple->columns[i] = pgsql_escape_identifier(pgsql, (char *) colname);

if (tuple->columns[i] == NULL)
{
Expand Down
Loading
0