Skip to content

Fix #181 - use version() instead, and if version query fails default to unknown version #194

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
Mar 19, 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
2 changes: 1 addition & 1 deletion src/include/postgres_version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace duckdb {

enum class PostgresInstanceType { POSTGRES, AURORA };
enum class PostgresInstanceType { UNKNOWN, POSTGRES, AURORA };

struct PostgresVersion {
PostgresVersion() {
Expand Down
7 changes: 6 additions & 1 deletion src/postgres_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ vector<unique_ptr<PostgresResult>> PostgresConnection::ExecuteQueries(const stri

PostgresVersion PostgresConnection::GetPostgresVersion() {
auto result =
Query("SELECT CURRENT_SETTING('server_version'), (SELECT COUNT(*) FROM pg_settings WHERE name LIKE 'rds%')");
TryQuery("SELECT version(), (SELECT COUNT(*) FROM pg_settings WHERE name LIKE 'rds%')");
if (!result) {
PostgresVersion version;
version.type_v = PostgresInstanceType::UNKNOWN;
return version;
}
auto version = PostgresUtils::ExtractPostgresVersion(result->GetString(0, 0));
if (result->GetInt64(0, 1) > 0) {
version.type_v = PostgresInstanceType::AURORA;
Expand Down
3 changes: 3 additions & 0 deletions src/postgres_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ uint32_t PostgresUtils::ToPostgresOid(const LogicalType &input) {
PostgresVersion PostgresUtils::ExtractPostgresVersion(const string &version_str) {
PostgresVersion result;
idx_t pos = 0;
if (!StringUtil::Contains(version_str, "PostgreSQL")) {
result.type_v = PostgresInstanceType::UNKNOWN;
}
// scan for the first digit
while (pos < version_str.size() && !StringUtil::CharacterIsDigit(version_str[pos])) {
pos++;
Expand Down
Loading