Skip to content

Commit

Permalink
Simplify sql query formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
VaibhaveS committed Aug 8, 2024
1 parent 46fc8d3 commit 3860989
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
34 changes: 6 additions & 28 deletions src/bin/pgcopydb/extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,28 +507,17 @@ timescaledb_pre_restore(CopyDataSpec *copySpecs, SourceExtension *extension)
return false;
}

PQExpBuffer sql = createPQExpBuffer();
char sql[128] = { 0 };
char *sqlTemplate = "select %s.timescaledb_pre_restore()";

appendPQExpBuffer(sql, sqlTemplate, extension->extnamespace);
sformat(sql, sizeof(sql), sqlTemplate, extension->extnamespace);

if (PQExpBufferBroken(sql))
if (!pgsql_execute(&dst, sql))
{
(void) destroyPQExpBuffer(sql);
log_error(
"Failed to allocate memory for SQL query string to get partition key range");
return false;
}

if (!pgsql_execute(&dst, sql->data))
{
(void) destroyPQExpBuffer(sql);
log_error("Failed to call %s.timescaledb_pre_restore()", extension->extnamespace);
return false;
}

(void) destroyPQExpBuffer(sql);

return true;
}

Expand All @@ -547,28 +536,17 @@ timescaledb_post_restore(CopyDataSpec *copySpecs, SourceExtension *extension)
return false;
}

PQExpBuffer sql = createPQExpBuffer();
char sql[128] = { 0 };
char *sqlTemplate = "select %s.timescaledb_post_restore()";

appendPQExpBuffer(sql, sqlTemplate, extension->extnamespace);
sformat(sql, sizeof(sql), sqlTemplate, extension->extnamespace);

if (PQExpBufferBroken(sql))
if (!pgsql_execute(&dst, sql))
{
(void) destroyPQExpBuffer(sql);
log_error(
"Failed to allocate memory for SQL query string to get partition key range");
return false;
}

if (!pgsql_execute(&dst, sql->data))
{
(void) destroyPQExpBuffer(sql);
log_error("Failed to call %s.timescaledb_post_restore()",
extension->extnamespace);
return false;
}

(void) destroyPQExpBuffer(sql);

return true;
}
11 changes: 11 additions & 0 deletions tests/timescaledb/copydb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,14 @@ diff $s $t

pgcopydb compare schema
pgcopydb compare data

# check timescaledb hypertables and chunks catalogs
psql -d ${PGCOPYDB_SOURCE_PGURI} -1 -c "SELECT * FROM timescaledb_information.hypertables" > /tmp/source_hypertables.out
psql -d ${PGCOPYDB_TARGET_PGURI} -1 -c "SELECT * FROM timescaledb_information.hypertables" > /tmp/target_hypertables.out

diff /tmp/source_hypertables.out /tmp/target_hypertables.out

psql -d ${PGCOPYDB_SOURCE_PGURI} -1 -c "SELECT * FROM timescaledb_information.chunks" > /tmp/source_chunks.out
psql -d ${PGCOPYDB_TARGET_PGURI} -1 -c "SELECT * FROM timescaledb_information.chunks" > /tmp/target_chunks.out

diff /tmp/source_chunks.out /tmp/target_chunks.out

0 comments on commit 3860989

Please sign in to comment.