Skip to content

Follow-up fix for Redshift: don't query pg_enum in older postgres versions #197

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 20, 2024
Merged
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/storage/postgres_type_set.hpp
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ class PostgresTypeSet : public PostgresInSchemaSet {
public:
optional_ptr<CatalogEntry> CreateType(ClientContext &context, CreateTypeInfo &info);

static string GetInitializeEnumsQuery();
static string GetInitializeEnumsQuery(PostgresVersion version);
static string GetInitializeCompositesQuery();

protected:
5 changes: 4 additions & 1 deletion src/storage/postgres_schema_set.cpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
#include "storage/postgres_transaction.hpp"
#include "duckdb/parser/parsed_data/create_schema_info.hpp"
#include "storage/postgres_table_set.hpp"
#include "storage/postgres_catalog.hpp"

namespace duckdb {

@@ -40,9 +41,11 @@ ORDER BY oid;
}

void PostgresSchemaSet::LoadEntries(ClientContext &context) {
auto &pg_catalog = catalog.Cast<PostgresCatalog>();
auto pg_version = pg_catalog.GetPostgresVersion();
string schema_query = PostgresSchemaSet::GetInitializeQuery();
string tables_query = PostgresTableSet::GetInitializeQuery();
string enum_types_query = PostgresTypeSet::GetInitializeEnumsQuery();
string enum_types_query = PostgresTypeSet::GetInitializeEnumsQuery(pg_version);
string composite_types_query = PostgresTypeSet::GetInitializeCompositesQuery();
string index_query = PostgresIndexSet::GetInitializeQuery();

10 changes: 9 additions & 1 deletion src/storage/postgres_type_set.cpp
Original file line number Diff line number Diff line change
@@ -20,7 +20,15 @@ PostgresTypeSet::PostgresTypeSet(PostgresSchemaEntry &schema, unique_ptr<Postgre
composite_type_result(std::move(composite_type_result_p)) {
}

string PostgresTypeSet::GetInitializeEnumsQuery() {
string PostgresTypeSet::GetInitializeEnumsQuery(PostgresVersion version) {
if (version.major_v < 8 || (version.major_v == 8 && version.minor_v < 3)) {
// pg_enum support has been present since v8.3 - https://www.postgresql.org/docs/8.3/catalog-pg-enum.html
// for older postgres versions we don't support enums instead
return R"(
SELECT 0 AS oid, 0 AS enumtypid, '' AS typname, '' AS enumlabel
LIMIT 0;
)";
}
return R"(
SELECT n.oid, enumtypid, typname, enumlabel
FROM pg_enum e

Unchanged files with check annotations Beta