From a436af52937303ed48927d5e7379a65af794876a Mon Sep 17 00:00:00 2001 From: Sascha Kuehl Date: Sun, 26 Nov 2023 20:12:13 +0100 Subject: [PATCH] implemented postgres table exists --- backends/postgres/src/postgres_connection.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backends/postgres/src/postgres_connection.cpp b/backends/postgres/src/postgres_connection.cpp index 4054f19..eb50d23 100644 --- a/backends/postgres/src/postgres_connection.cpp +++ b/backends/postgres/src/postgres_connection.cpp @@ -134,7 +134,13 @@ sql::record postgres_connection::describe(const std::string &table) bool postgres_connection::exists(const std::string &table_name) { - return false; + std::string stmt("SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = '" + table_name + "'"); + + PGresult *res = PQexec(conn_, stmt.c_str()); + + throw_postgres_error(res, conn_, "postgres", stmt); + + return sql::to_long_long(PQcmdTuples(res)) == 1; } }