Skip to content

Commit 656ab0b

Browse files
authored
Merge pull request #197 from Mytherin/redshift2
Follow-up fix for Redshift: don't query pg_enum in older postgres versions
2 parents 0e39a01 + d92dda4 commit 656ab0b

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/include/storage/postgres_type_set.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class PostgresTypeSet : public PostgresInSchemaSet {
2525
public:
2626
optional_ptr<CatalogEntry> CreateType(ClientContext &context, CreateTypeInfo &info);
2727

28-
static string GetInitializeEnumsQuery();
28+
static string GetInitializeEnumsQuery(PostgresVersion version);
2929
static string GetInitializeCompositesQuery();
3030

3131
protected:

src/storage/postgres_schema_set.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "storage/postgres_transaction.hpp"
66
#include "duckdb/parser/parsed_data/create_schema_info.hpp"
77
#include "storage/postgres_table_set.hpp"
8+
#include "storage/postgres_catalog.hpp"
89

910
namespace duckdb {
1011

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

4243
void PostgresSchemaSet::LoadEntries(ClientContext &context) {
44+
auto &pg_catalog = catalog.Cast<PostgresCatalog>();
45+
auto pg_version = pg_catalog.GetPostgresVersion();
4346
string schema_query = PostgresSchemaSet::GetInitializeQuery();
4447
string tables_query = PostgresTableSet::GetInitializeQuery();
45-
string enum_types_query = PostgresTypeSet::GetInitializeEnumsQuery();
48+
string enum_types_query = PostgresTypeSet::GetInitializeEnumsQuery(pg_version);
4649
string composite_types_query = PostgresTypeSet::GetInitializeCompositesQuery();
4750
string index_query = PostgresIndexSet::GetInitializeQuery();
4851

src/storage/postgres_type_set.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ PostgresTypeSet::PostgresTypeSet(PostgresSchemaEntry &schema, unique_ptr<Postgre
2020
composite_type_result(std::move(composite_type_result_p)) {
2121
}
2222

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

0 commit comments

Comments
 (0)