mirror of https://github.com/citusdata/citus.git
Fix bugs in CheckIfRelationWithSameNameExists (#6343)
Co-authored-by: Marco Slot <marco.slot@gmail.com>pull/6355/head
parent
3f33390f45
commit
eba70af7a2
|
@ -670,10 +670,15 @@ CheckIfRelationWithSameNameExists(ShardInterval *shardInterval, WorkerNode *work
|
||||||
AppendShardIdToName(&shardName, shardInterval->shardId);
|
AppendShardIdToName(&shardName, shardInterval->shardId);
|
||||||
|
|
||||||
StringInfo checkShardExistsQuery = makeStringInfo();
|
StringInfo checkShardExistsQuery = makeStringInfo();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We pass schemaName and shardName without quote_identifier, since
|
||||||
|
* they are used as strings here.
|
||||||
|
*/
|
||||||
appendStringInfo(checkShardExistsQuery,
|
appendStringInfo(checkShardExistsQuery,
|
||||||
"SELECT EXISTS (SELECT FROM pg_catalog.pg_tables WHERE schemaname = '%s' AND tablename = '%s');",
|
"SELECT EXISTS (SELECT FROM pg_catalog.pg_tables WHERE schemaname = %s AND tablename = %s);",
|
||||||
schemaName,
|
quote_literal_cstr(schemaName),
|
||||||
shardName);
|
quote_literal_cstr(shardName));
|
||||||
|
|
||||||
int connectionFlags = 0;
|
int connectionFlags = 0;
|
||||||
MultiConnection *connection = GetNodeUserDatabaseConnection(connectionFlags,
|
MultiConnection *connection = GetNodeUserDatabaseConnection(connectionFlags,
|
||||||
|
@ -691,11 +696,13 @@ CheckIfRelationWithSameNameExists(ShardInterval *shardInterval, WorkerNode *work
|
||||||
ReportResultError(connection, result, ERROR);
|
ReportResultError(connection, result, ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *checkExists = PQgetvalue(result, 0, 0);
|
char *existsString = PQgetvalue(result, 0, 0);
|
||||||
|
bool tableExists = strcmp(existsString, "t") == 0;
|
||||||
|
|
||||||
PQclear(result);
|
PQclear(result);
|
||||||
ForgetResults(connection);
|
ForgetResults(connection);
|
||||||
|
|
||||||
return strcmp(checkExists, "t") == 0;
|
return tableExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue