diff --git a/database-connector b/database-connector index 53e5627b4..7777dac88 160000 --- a/database-connector +++ b/database-connector @@ -1 +1 @@ -Subproject commit 53e5627b4e30e29a47a66a3d239385d6fc8528c0 +Subproject commit 7777dac887a48769684900a627ecaaf6feb3f4c5 diff --git a/duckdb b/duckdb index be587a70e..d8f343577 160000 --- a/duckdb +++ b/duckdb @@ -1 +1 @@ -Subproject commit be587a70ee5eae815e333ca121d39b6905f34535 +Subproject commit d8f343577c04ab84c32c19f201e1082ea6fa8ade diff --git a/extension-ci-tools b/extension-ci-tools index 69338b624..a00c74e02 160000 --- a/extension-ci-tools +++ b/extension-ci-tools @@ -1 +1 @@ -Subproject commit 69338b62443a27122b44a4898e044e3f2dd9a621 +Subproject commit a00c74e02aefbfa3fd31a4c74c4b6bc260af0de7 diff --git a/src/include/postgres_binary_copy.hpp b/src/include/postgres_binary_copy.hpp index 7119cd8ce..fe873fc1a 100644 --- a/src/include/postgres_binary_copy.hpp +++ b/src/include/postgres_binary_copy.hpp @@ -19,7 +19,7 @@ class PostgresBinaryCopyFunction : public CopyFunction { PostgresBinaryCopyFunction(); static unique_ptr PostgresBinaryWriteBind(ClientContext &context, CopyFunctionBindInput &input, - const vector &names, + const vector &names, const vector &sql_types); static unique_ptr diff --git a/src/include/storage/postgres_index_entry.hpp b/src/include/storage/postgres_index_entry.hpp index c800f23ed..b4684214b 100644 --- a/src/include/storage/postgres_index_entry.hpp +++ b/src/include/storage/postgres_index_entry.hpp @@ -19,8 +19,8 @@ class PostgresIndexEntry : public IndexCatalogEntry { string table_name; public: - string GetSchemaName() const override; - string GetTableName() const override; + Identifier GetSchemaName() const override; + Identifier GetTableName() const override; }; } // namespace duckdb diff --git a/src/include/storage/postgres_secret_storage.hpp b/src/include/storage/postgres_secret_storage.hpp index 8eda172a0..3504fe208 100644 --- a/src/include/storage/postgres_secret_storage.hpp +++ b/src/include/storage/postgres_secret_storage.hpp @@ -43,7 +43,7 @@ class PostgresSecretStorage : public SecretStorage { unique_ptr StoreSecret(unique_ptr secret, OnCreateConflict on_conflict, optional_ptr transaction = nullptr) override; vector AllSecrets(optional_ptr transaction = nullptr) override; - void DropSecretByName(const string &name, OnEntryNotFound on_entry_not_found, + void DropSecretByName(const Identifier &name, OnEntryNotFound on_entry_not_found, optional_ptr transaction = nullptr) override; SecretMatch LookupSecret(const string &path, const string &type, optional_ptr transaction = nullptr) override; diff --git a/src/include/storage/postgres_table_entry.hpp b/src/include/storage/postgres_table_entry.hpp index b97677c39..f21f8c3fb 100644 --- a/src/include/storage/postgres_table_entry.hpp +++ b/src/include/storage/postgres_table_entry.hpp @@ -20,16 +20,16 @@ struct PostgresTableInfo { create_info->columns.SetAllowDuplicates(true); } PostgresTableInfo(const string &schema, const string &table) { - create_info = make_uniq(string(), schema, table); + create_info = make_uniq(Identifier(), Identifier(schema), Identifier(table)); create_info->columns.SetAllowDuplicates(true); } PostgresTableInfo(const SchemaCatalogEntry &schema, const string &table) { - create_info = make_uniq((SchemaCatalogEntry &)schema, table); + create_info = make_uniq((SchemaCatalogEntry &)schema, Identifier(table)); create_info->columns.SetAllowDuplicates(true); } const string &GetTableName() const { - return create_info->table; + return create_info->table.GetIdentifierName(); } unique_ptr create_info; diff --git a/src/postgres_aws.cpp b/src/postgres_aws.cpp index 79776dc32..708c89889 100644 --- a/src/postgres_aws.cpp +++ b/src/postgres_aws.cpp @@ -90,7 +90,7 @@ std::string PostgresAws::GenerateRdsAuthToken(AttachedDatabase &attached_db, } static std::string ExtractString(const KeyValueSecret &kv, const std::string name) { - Value val = kv.TryGetValue(name); + Value val = kv.TryGetValue(Identifier(name)); if (val.IsNull()) { return std::string(); } diff --git a/src/postgres_binary_copy.cpp b/src/postgres_binary_copy.cpp index d5c75902b..0ceafa61e 100644 --- a/src/postgres_binary_copy.cpp +++ b/src/postgres_binary_copy.cpp @@ -56,7 +56,7 @@ struct PostgresBinaryWriteBindData : public TableFunctionData {}; unique_ptr PostgresBinaryCopyFunction::PostgresBinaryWriteBind(ClientContext &context, CopyFunctionBindInput &input, - const vector &names, + const vector &names, const vector &sql_types) { return make_uniq(); } @@ -172,7 +172,7 @@ static unique_ptr ReadPostgresBinaryBind(ClientContext &context, T auto col_type_str = column_map[i].GetValue(); auto col_type = TransformStringToLogicalType(col_type_str, context); - names.push_back(col_name); + names.push_back(col_name.GetIdentifierName()); return_types.push_back(col_type); result->postgres_types.push_back(PostgresUtils::CreateEmptyPostgresType(col_type)); } diff --git a/src/postgres_execute.cpp b/src/postgres_execute.cpp index ea9f6bbc1..46caebb1f 100644 --- a/src/postgres_execute.cpp +++ b/src/postgres_execute.cpp @@ -28,7 +28,7 @@ static duckdb::unique_ptr PGExecuteBind(ClientContext &context, Ta // look up the database to query auto db_name = input.inputs[0].GetValue(); auto &db_manager = DatabaseManager::Get(context); - auto db = db_manager.GetDatabase(context, db_name); + auto db = db_manager.GetDatabase(context, Identifier(db_name)); if (!db) { throw BinderException("Failed to find attached database \"%s\" referenced in postgres_query", db_name); } diff --git a/src/postgres_query.cpp b/src/postgres_query.cpp index f999617dd..89ce56ef0 100644 --- a/src/postgres_query.cpp +++ b/src/postgres_query.cpp @@ -21,7 +21,7 @@ static unique_ptr PGQueryBind(ClientContext &context, TableFunctio // look up the database to query auto db_name = input.inputs[0].GetValue(); auto &db_manager = DatabaseManager::Get(context); - auto db = db_manager.GetDatabase(context, db_name); + auto db = db_manager.GetDatabase(context, Identifier(db_name)); if (!db) { throw BinderException("Failed to find attached database \"%s\" referenced in postgres_query", db_name); } diff --git a/src/postgres_scanner.cpp b/src/postgres_scanner.cpp index a1a605ed2..7c44cdc46 100644 --- a/src/postgres_scanner.cpp +++ b/src/postgres_scanner.cpp @@ -200,7 +200,7 @@ static unique_ptr PostgresBind(ClientContext &context, TableFuncti bind_data->postgres_types = info->postgres_types; for (auto &col : info->create_info->columns.Logical()) { - names.push_back(col.GetName()); + names.push_back(col.GetName().GetIdentifierName()); return_types.push_back(col.GetType()); } bind_data->names = info->postgres_names; diff --git a/src/postgres_secrets.cpp b/src/postgres_secrets.cpp index 9500d38a3..8d3dddc55 100644 --- a/src/postgres_secrets.cpp +++ b/src/postgres_secrets.cpp @@ -112,7 +112,7 @@ unique_ptr PostgresSecrets::CreateFunction(ClientContext &context, C std::find(other_option_names.begin(), other_option_names.end(), name) == other_option_names.end()) { throw InternalException("Unknown named parameter for a Postgres secret: '" + named_param.first + "'"); } - result->secret_map[name] = named_param.second.ToString(); + result->secret_map[Identifier(name)] = named_param.second.ToString(); } result->redact_keys = {"password", "sslpassword", "oauth_client_secret", "uri"}; return std::move(result); @@ -120,10 +120,10 @@ unique_ptr PostgresSecrets::CreateFunction(ClientContext &context, C void PostgresSecrets::SetSecretParameters(CreateSecretFunction &function) { for (const std::string &name : connection_option_names) { - function.named_parameters[name] = LogicalType::VARCHAR; + function.named_parameters[Identifier(name)] = LogicalType::VARCHAR; } for (auto &en : connection_option_aliases) { - function.named_parameters[en.first] = LogicalType::VARCHAR; + function.named_parameters[Identifier(en.first)] = LogicalType::VARCHAR; } // other options function.named_parameters["uri"] = LogicalType::VARCHAR; diff --git a/src/postgres_utils.cpp b/src/postgres_utils.cpp index 79227c59a..e60bccd4a 100644 --- a/src/postgres_utils.cpp +++ b/src/postgres_utils.cpp @@ -249,11 +249,12 @@ LogicalType PostgresUtils::TypeToLogicalType(optional_ptr t throw InternalException("Context is destroyed!?"); } optional_ptr lookup_schema = - type_info.type_schema != schema->name - ? schema->ParentCatalog().GetSchema(*context, type_info.type_schema, OnEntryNotFound::THROW_EXCEPTION) + Identifier(type_info.type_schema) != schema->name + ? schema->ParentCatalog().GetSchema(*context, Identifier(type_info.type_schema), + OnEntryNotFound::THROW_EXCEPTION) : schema.get(); auto entry = lookup_schema->GetEntry(CatalogTransaction(lookup_schema->ParentCatalog(), *context), - CatalogType::TYPE_ENTRY, pgtypename); + CatalogType::TYPE_ENTRY, Identifier(pgtypename)); if (!entry) { // unsupported so fallback to varchar postgres_type.info = PostgresTypeAnnotation::CAST_TO_VARCHAR; @@ -555,7 +556,7 @@ string PostgresUtils::EscapeConnectionString(const string &input) { } string PostgresUtils::ExtractConnectionOption(const KeyValueSecret &kv_secret, const string &name) { - Value input_val = kv_secret.TryGetValue(name); + Value input_val = kv_secret.TryGetValue(Identifier(name)); if (input_val.IsNull()) { // not provided return string(); diff --git a/src/storage/postgres_catalog.cpp b/src/storage/postgres_catalog.cpp index 4754e6bf3..64c6305db 100644 --- a/src/storage/postgres_catalog.cpp +++ b/src/storage/postgres_catalog.cpp @@ -118,7 +118,7 @@ string PostgresCatalog::CreateConnectionString(optional_ptr secret_ if (!uri_val.IsNull()) { // no other options can be specified along with the URI for (const string &opt_name : PostgresSecrets::ConnectionOptionNames()) { - if (!kv_secret.TryGetValue(opt_name).IsNull()) { + if (!kv_secret.TryGetValue(Identifier(opt_name)).IsNull()) { throw BinderException("Options with name \"%s\" cannot be specified when 'URI' option is specified", opt_name); } @@ -175,7 +175,7 @@ void PostgresCatalog::Initialize(bool load_builtin) { optional_ptr PostgresCatalog::CreateSchema(CatalogTransaction transaction, CreateSchemaInfo &info) { auto &postgres_transaction = PostgresTransaction::Get(transaction.GetContext(), *this); - auto entry = schemas.GetEntry(transaction.GetContext(), postgres_transaction, info.schema); + auto entry = schemas.GetEntry(transaction.GetContext(), postgres_transaction, info.schema.GetIdentifierName()); if (entry) { switch (info.on_conflict) { case OnCreateConflict::REPLACE_ON_CONFLICT: { @@ -259,7 +259,7 @@ void PostgresCatalog::RegisterSecretStorage() { auto connection = connection_pool->GetConnection(); bool secret_storage_table_exists = secret_storage_table.Exists(connection.GetConnection()); - string attached_database_name = GetAttached().GetName(); + string attached_database_name = GetAttached().GetName().GetIdentifierName(); if (!secret_storage_table_exists) { if (!secret_storage_table.specified_explicitly) { diff --git a/src/storage/postgres_catalog_set.cpp b/src/storage/postgres_catalog_set.cpp index c9e7c8bb7..2243adb2a 100644 --- a/src/storage/postgres_catalog_set.cpp +++ b/src/storage/postgres_catalog_set.cpp @@ -67,9 +67,9 @@ void PostgresCatalogSet::DropEntry(PostgresTransaction &transaction, DropInfo &i drop_query += " IF EXISTS "; } if (!info.schema.empty()) { - drop_query += PostgresUtils::WriteIdentifier(info.schema) + "."; + drop_query += PostgresUtils::WriteIdentifier(info.schema.GetIdentifierName()) + "."; } - drop_query += PostgresUtils::WriteIdentifier(info.name); + drop_query += PostgresUtils::WriteIdentifier(info.name.GetIdentifierName()); if (info.cascade) { drop_query += "CASCADE"; } @@ -77,7 +77,7 @@ void PostgresCatalogSet::DropEntry(PostgresTransaction &transaction, DropInfo &i // erase the entry from the catalog set lock_guard l(entry_lock); - entries.erase(info.name); + entries.erase(info.name.GetIdentifierName()); } void PostgresCatalogSet::Scan(ClientContext &context, PostgresTransaction &transaction, diff --git a/src/storage/postgres_configure_pool.cpp b/src/storage/postgres_configure_pool.cpp index 9209dbe45..2032b2346 100644 --- a/src/storage/postgres_configure_pool.cpp +++ b/src/storage/postgres_configure_pool.cpp @@ -25,7 +25,7 @@ struct ConfigurePoolBindData : public TableFunctionData { std::pair health_check_query; static Value Lookup(const named_parameter_map_t &map, const std::string &key) { - auto it = map.find(key); + auto it = map.find(Identifier(key)); if (it == map.end()) { return Value(); } @@ -156,10 +156,10 @@ static void ConfigurePoolFunction(ClientContext &context, TableFunctionInput &in if (catalog.GetCatalogType() != "postgres") { continue; } - if (!bdata.catalog_name.second && catalog.GetName() != bdata.catalog_name.first) { + if (!bdata.catalog_name.second && catalog.GetName() != Identifier(bdata.catalog_name.first)) { continue; } - cat_names.push_back(catalog.GetName()); + cat_names.push_back(catalog.GetName().GetIdentifierName()); shared_ptr pool = catalog.Cast().GetConnectionPoolPtr(); pools.emplace_back(std::move(pool)); } diff --git a/src/storage/postgres_delete.cpp b/src/storage/postgres_delete.cpp index aab45b3d4..97b829fff 100644 --- a/src/storage/postgres_delete.cpp +++ b/src/storage/postgres_delete.cpp @@ -21,8 +21,8 @@ PostgresDelete::PostgresDelete(PhysicalPlan &physical_plan, LogicalOperator &op, string GetDeleteSQL(const PostgresTableEntry &table, const string &ctid_list) { string result; result = "DELETE FROM "; - result += PostgresUtils::WriteIdentifier(table.schema.name) + "."; - result += PostgresUtils::QuotePostgresIdentifier(table.name); + result += PostgresUtils::WriteIdentifier(table.schema.name.GetIdentifierName()) + "."; + result += PostgresUtils::QuotePostgresIdentifier(table.name.GetIdentifierName()); result += " WHERE ctid IN (" + ctid_list + ")"; return result; } @@ -115,7 +115,7 @@ string PostgresDelete::GetName() const { InsertionOrderPreservingMap PostgresDelete::ParamsToString() const { InsertionOrderPreservingMap result; - result["Table Name"] = table.name; + result["Table Name"] = table.name.GetIdentifierName(); return result; } diff --git a/src/storage/postgres_index_entry.cpp b/src/storage/postgres_index_entry.cpp index a27ab3eab..0f42ef32d 100644 --- a/src/storage/postgres_index_entry.cpp +++ b/src/storage/postgres_index_entry.cpp @@ -8,12 +8,12 @@ PostgresIndexEntry::PostgresIndexEntry(Catalog &catalog, SchemaCatalogEntry &sch : IndexCatalogEntry(catalog, schema, info), table_name(std::move(table_name_p)) { } -string PostgresIndexEntry::GetSchemaName() const { +Identifier PostgresIndexEntry::GetSchemaName() const { return schema.name; } -string PostgresIndexEntry::GetTableName() const { - return table_name; +Identifier PostgresIndexEntry::GetTableName() const { + return Identifier(table_name); } } // namespace duckdb diff --git a/src/storage/postgres_index_set.cpp b/src/storage/postgres_index_set.cpp index fd8235818..e4f4c6e78 100644 --- a/src/storage/postgres_index_set.cpp +++ b/src/storage/postgres_index_set.cpp @@ -40,8 +40,8 @@ void PostgresIndexSet::LoadEntries(ClientContext &context, PostgresTransaction & auto index_name = result.GetString(row, 2); CreateIndexInfo info; info.schema = schema.name; - info.table = table_name; - info.index_name = index_name; + info.table = Identifier(table_name); + info.index_name = Identifier(index_name); auto index_entry = make_shared_ptr(catalog, schema, info, table_name); CreateEntry(transaction, std::move(index_entry)); } @@ -65,10 +65,10 @@ string PGGetCreateIndexSQL(CreateIndexInfo &info, TableCatalogEntry &tbl) { sql += " UNIQUE"; } sql += " INDEX "; - sql += PostgresUtils::QuotePostgresIdentifier(info.index_name); + sql += PostgresUtils::QuotePostgresIdentifier(info.index_name.GetIdentifierName()); sql += " ON "; - sql += PostgresUtils::QuotePostgresIdentifier(tbl.schema.name) + "."; - sql += PostgresUtils::QuotePostgresIdentifier(tbl.name); + sql += PostgresUtils::QuotePostgresIdentifier(tbl.schema.name.GetIdentifierName()) + "."; + sql += PostgresUtils::QuotePostgresIdentifier(tbl.name.GetIdentifierName()); sql += "("; for (idx_t i = 0; i < info.parsed_expressions.size(); i++) { if (i > 0) { @@ -84,7 +84,8 @@ string PGGetCreateIndexSQL(CreateIndexInfo &info, TableCatalogEntry &tbl) { optional_ptr PostgresIndexSet::CreateIndex(PostgresTransaction &transaction, CreateIndexInfo &info, TableCatalogEntry &table) { transaction.Query(PGGetCreateIndexSQL(info, table)); - auto index_entry = make_shared_ptr(schema.ParentCatalog(), schema, info, table.name); + auto index_entry = + make_shared_ptr(schema.ParentCatalog(), schema, info, table.name.GetIdentifierName()); return CreateEntry(transaction, std::move(index_entry)); } diff --git a/src/storage/postgres_insert.cpp b/src/storage/postgres_insert.cpp index 3bf1c0205..467b995b9 100644 --- a/src/storage/postgres_insert.cpp +++ b/src/storage/postgres_insert.cpp @@ -72,7 +72,7 @@ vector GetInsertColumns(const PostgresInsert &insert, PostgresTableEntry } for (idx_t c = 0; c < column_count; c++) { auto &col = columns.GetColumn(column_indexes[c]); - column_names.push_back(col.GetName()); + column_names.push_back(col.GetName().GetIdentifierName()); } } return column_names; @@ -95,7 +95,8 @@ unique_ptr PostgresInsert::GetGlobalSinkState(ClientContext &co auto &insert_column_names = result->insert_column_names; if (!insert_columns.empty()) { for (auto &str : insert_columns) { - auto index = insert_table->GetColumnIndex(str, true); + Identifier col_identifier(str); + auto index = insert_table->GetColumnIndex(col_identifier, true); if (!index.IsValid()) { insert_column_names.push_back(str); } else { @@ -115,8 +116,9 @@ SinkResultType PostgresInsert::Sink(ExecutionContext &context, DataChunk &chunk, auto &connection = transaction.GetConnection(); if (!gstate.copy_is_active) { // copy hasn't started yet - connection.BeginCopyTo(context.client, gstate.copy_state, gstate.format, gstate.table.schema.name, - gstate.table.name, gstate.insert_column_names); + connection.BeginCopyTo(context.client, gstate.copy_state, gstate.format, + gstate.table.schema.name.GetIdentifierName(), gstate.table.name.GetIdentifierName(), + gstate.insert_column_names); gstate.copy_is_active = true; } connection.CopyChunk(context.client, gstate.copy_state, chunk, gstate.varchar_chunk); @@ -166,7 +168,7 @@ string PostgresInsert::GetName() const { InsertionOrderPreservingMap PostgresInsert::ParamsToString() const { InsertionOrderPreservingMap result; - result["Table Name"] = table ? table->name : info->Base().table; + result["Table Name"] = table ? table->name.GetIdentifierName() : info->Base().table.GetIdentifierName(); return result; } @@ -219,7 +221,7 @@ bool PostgresCatalog::IsPostgresScan(const string &name) { void PostgresCatalog::MaterializePostgresScans(PhysicalOperator &op) { if (op.type == PhysicalOperatorType::TABLE_SCAN) { auto &table_scan = op.Cast(); - if (PostgresCatalog::IsPostgresScan(table_scan.function.name)) { + if (PostgresCatalog::IsPostgresScan(table_scan.function.name.GetIdentifierName())) { auto &bind_data = table_scan.bind_data->Cast(); bind_data.requires_materialization = true; bind_data.max_threads = 1; diff --git a/src/storage/postgres_optimizer.cpp b/src/storage/postgres_optimizer.cpp index 831c20981..a035516c4 100644 --- a/src/storage/postgres_optimizer.cpp +++ b/src/storage/postgres_optimizer.cpp @@ -22,7 +22,7 @@ static void GatherPostgresScans(LogicalOperator &op, PostgresOperators &result) if (op.type == LogicalOperatorType::LOGICAL_GET) { auto &get = op.Cast(); auto &table_scan = get.function; - if (!PostgresCatalog::IsPostgresScan(table_scan.name)) { + if (!PostgresCatalog::IsPostgresScan(table_scan.name.GetIdentifierName())) { // not a postgres scan - skip return; } diff --git a/src/storage/postgres_schema_entry.cpp b/src/storage/postgres_schema_entry.cpp index d4b16cd52..f320e6f57 100644 --- a/src/storage/postgres_schema_entry.cpp +++ b/src/storage/postgres_schema_entry.cpp @@ -42,7 +42,7 @@ PostgresTransaction &GetPostgresTransaction(CatalogTransaction transaction) { void PostgresSchemaEntry::TryDropEntry(ClientContext &context, CatalogType catalog_type, const string &name) { DropInfo info; info.type = catalog_type; - info.name = name; + info.name = Identifier(name); info.cascade = false; info.if_not_found = OnEntryNotFound::RETURN_NULL; DropEntry(context, info); @@ -52,7 +52,7 @@ optional_ptr PostgresSchemaEntry::CreateTable(CatalogTransaction t BoundCreateTableInfo &info) { auto &postgres_transaction = GetPostgresTransaction(transaction); auto &base_info = info.Base(); - auto table_name = base_info.table; + string table_name = base_info.table.GetIdentifierName(); if (base_info.on_conflict == OnCreateConflict::REPLACE_ON_CONFLICT) { // CREATE OR REPLACE - drop any existing entries first (if any) TryDropEntry(transaction.GetContext(), CatalogType::TABLE_ENTRY, table_name); @@ -74,8 +74,8 @@ optional_ptr PostgresSchemaEntry::CreateIndex(CatalogTransaction t string PGGetCreateViewSQL(PostgresSchemaEntry &schema, CreateViewInfo &info) { string sql; sql = "CREATE VIEW "; - sql += PostgresUtils::QuotePostgresIdentifier(schema.name) + "."; - sql += PostgresUtils::QuotePostgresIdentifier(info.view_name); + sql += PostgresUtils::QuotePostgresIdentifier(schema.name.GetIdentifierName()) + "."; + sql += PostgresUtils::QuotePostgresIdentifier(info.view_name.GetIdentifierName()); sql += " "; if (!info.aliases.empty()) { sql += "("; @@ -84,7 +84,7 @@ string PGGetCreateViewSQL(PostgresSchemaEntry &schema, CreateViewInfo &info) { sql += ", "; } auto &alias = info.aliases[i]; - sql += PostgresUtils::QuotePostgresIdentifier(alias); + sql += PostgresUtils::QuotePostgresIdentifier(alias.GetIdentifierName()); } sql += ") "; } @@ -105,12 +105,12 @@ optional_ptr PostgresSchemaEntry::CreateView(CatalogTransaction tr return current_entry; } // CREATE OR REPLACE - drop any existing entries first (if any) - TryDropEntry(transaction.GetContext(), CatalogType::VIEW_ENTRY, info.view_name); + TryDropEntry(transaction.GetContext(), CatalogType::VIEW_ENTRY, info.view_name.GetIdentifierName()); } } auto &postgres_transaction = GetPostgresTransaction(transaction); postgres_transaction.Query(PGGetCreateViewSQL(*this, info)); - return tables.ReloadEntry(postgres_transaction, info.view_name); + return tables.ReloadEntry(postgres_transaction, info.view_name.GetIdentifierName()); } optional_ptr PostgresSchemaEntry::CreateType(CatalogTransaction transaction, CreateTypeInfo &info) { @@ -118,7 +118,7 @@ optional_ptr PostgresSchemaEntry::CreateType(CatalogTransaction tr auto type_name = info.name; if (info.on_conflict == OnCreateConflict::REPLACE_ON_CONFLICT) { // CREATE OR REPLACE - drop any existing entries first (if any) - TryDropEntry(transaction.GetContext(), CatalogType::TYPE_ENTRY, info.name); + TryDropEntry(transaction.GetContext(), CatalogType::TYPE_ENTRY, info.name.GetIdentifierName()); } return types.CreateType(postgres_transaction, info); } diff --git a/src/storage/postgres_schema_set.cpp b/src/storage/postgres_schema_set.cpp index 197d15c03..d5613c773 100644 --- a/src/storage/postgres_schema_set.cpp +++ b/src/storage/postgres_schema_set.cpp @@ -75,7 +75,7 @@ void PostgresSchemaSet::LoadEntries(ClientContext &context, PostgresTransaction auto oid = result->GetInt64(row, 0); auto schema_name = result->GetString(row, 1); CreateSchemaInfo info; - info.schema = schema_name; + info.schema = Identifier(schema_name); info.internal = PostgresSchemaEntry::SchemaIsInternal(schema_name); auto schema = make_shared_ptr(catalog, info, std::move(tables[row]), std::move(enums[row]), std::move(composite_types[row]), std::move(indexes[row])); @@ -88,10 +88,10 @@ optional_ptr PostgresSchemaSet::CreateSchema(PostgresTransaction & if (info.on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT) { create_sql += " IF NOT EXISTS"; } - create_sql += PostgresUtils::WriteIdentifier(info.schema); + create_sql += PostgresUtils::WriteIdentifier(info.schema.GetIdentifierName()); transaction.Query(create_sql); auto info_copy = info.Copy(); - info.internal = PostgresSchemaEntry::SchemaIsInternal(info_copy->schema); + info.internal = PostgresSchemaEntry::SchemaIsInternal(info_copy->schema.GetIdentifierName()); auto schema_entry = make_shared_ptr(catalog, info_copy->Cast()); return CreateEntry(transaction, std::move(schema_entry)); } diff --git a/src/storage/postgres_secret_storage.cpp b/src/storage/postgres_secret_storage.cpp index 302b78a8e..881221e02 100644 --- a/src/storage/postgres_secret_storage.cpp +++ b/src/storage/postgres_secret_storage.cpp @@ -121,7 +121,7 @@ PostgresSecretStorage::~PostgresSecretStorage() { optional_ptr PostgresSecretStorage::GetPostgresCatalog(ClientContext &context) { auto &db_manager = DatabaseManager::Get(context); - auto attached_db = db_manager.GetDatabase(context, attached_database_name); + auto attached_db = db_manager.GetDatabase(context, Identifier(attached_database_name)); if (!attached_db) { return nullptr; } @@ -178,8 +178,8 @@ unique_ptr PostgresSecretStorage::DeserializeSecret(PostgresCa unique_ptr PostgresSecretStorage::StoreSecret(unique_ptr secret, OnCreateConflict on_conflict, optional_ptr transaction) { - auto secret_name = secret->GetName(); - auto secret_type = secret->GetType(); + string secret_name = secret->GetName().GetIdentifierName(); + string secret_type = secret->GetType().GetIdentifierName(); // Check if secret already exists auto existing = GetSecretByName(secret_name, transaction); @@ -274,7 +274,7 @@ vector PostgresSecretStorage::AllSecrets(optional_ptr transaction) { auto &context = transaction->GetContext(); auto postgres_catalog_ptr = GetPostgresCatalog(context); @@ -287,16 +287,16 @@ void PostgresSecretStorage::DropSecretByName(const string &name, OnEntryNotFound auto &postgres_catalog = *postgres_catalog_ptr; // Check if secret exists - auto existing = GetSecretByName(name, transaction); + auto existing = GetSecretByName(name.GetIdentifierName(), transaction); if (!existing && on_entry_not_found == OnEntryNotFound::THROW_EXCEPTION) { - throw InvalidInputException("Failed to remove non-existent persistent secret '%s' in secret storage '%s'", name, - storage_name); + throw InvalidInputException("Failed to remove non-existent persistent secret '%s' in secret storage '%s'", + name.GetIdentifierName(), storage_name); } auto &postgres_transaction = PostgresTransaction::Get(context, postgres_catalog); // Delete the secret - string escaped_name = EscapeSQLString(name); + string escaped_name = EscapeSQLString(name.GetIdentifierName()); string query = StringUtil::Format("DELETE FROM %s WHERE secret_name = '%s'", secrets_table_name, escaped_name); postgres_transaction.Query(query); } diff --git a/src/storage/postgres_table_entry.cpp b/src/storage/postgres_table_entry.cpp index a746a456b..8479e8bb9 100644 --- a/src/storage/postgres_table_entry.cpp +++ b/src/storage/postgres_table_entry.cpp @@ -16,7 +16,7 @@ PostgresTableEntry::PostgresTableEntry(Catalog &catalog, SchemaCatalogEntry &sch col.TypeMutable() = PostgresUtils::RemoveAlias(col.GetType()); } postgres_types.push_back(PostgresUtils::CreateEmptyPostgresType(col.GetType())); - postgres_names.push_back(col.GetName()); + postgres_names.push_back(col.GetName().GetIdentifierName()); } approx_num_pages.store(0, std::memory_order_release); } @@ -42,8 +42,8 @@ TableFunction PostgresTableEntry::GetScanFunction(ClientContext &context, unique auto result = make_uniq(context); - result->schema_name = schema.name; - result->table_name = name; + result->schema_name = schema.name.GetIdentifierName(); + result->table_name = name.GetIdentifierName(); result->dsn = transaction.GetDSN(); result->attach_path = pg_catalog.attach_path; result->SetCatalog(pg_catalog); diff --git a/src/storage/postgres_table_set.cpp b/src/storage/postgres_table_set.cpp index b7edc4710..663e6d523 100644 --- a/src/storage/postgres_table_set.cpp +++ b/src/storage/postgres_table_set.cpp @@ -81,7 +81,7 @@ void PostgresTableSet::AddColumn(optional_ptr transaction, auto column_type = PostgresUtils::TypeToLogicalType(transaction, schema, type_info, postgres_type); table_info.postgres_types.push_back(std::move(postgres_type)); table_info.postgres_names.push_back(column_name); - ColumnDefinition column(std::move(column_name), std::move(column_type)); + ColumnDefinition column(Identifier(std::move(column_name)), std::move(column_type)); if (!column_comment.empty()) { column.SetComment(Value(column_comment)); } @@ -112,7 +112,7 @@ void PostgresTableSet::AddConstraint(PostgresResult &result, idx_t row, Postgres auto &create_info = *table_info.create_info; auto splits = StringUtil::Split(constraint_key.substr(1, constraint_key.size() - 2), ","); - vector columns; + vector columns; for (auto &split : splits) { auto index = std::stoull(split); if (index <= 0 || index > create_info.columns.LogicalColumnCount()) { @@ -168,7 +168,7 @@ void PostgresTableSet::LoadEntries(ClientContext &context, PostgresTransaction & CreateEntries(transaction, table_result->GetResult(), table_result->start, table_result->end); table_result.reset(); } else { - auto query = GetInitializeQuery(schema.name); + auto query = GetInitializeQuery(schema.name.GetIdentifierName()); auto result = transaction.Query(query); auto rows = result->Count(); @@ -179,7 +179,7 @@ void PostgresTableSet::LoadEntries(ClientContext &context, PostgresTransaction & unique_ptr PostgresTableSet::GetTableInfo(PostgresTransaction &transaction, PostgresSchemaEntry &schema, const string &table_name) { - auto query = PostgresTableSet::GetInitializeQuery(schema.name, table_name); + auto query = PostgresTableSet::GetInitializeQuery(schema.name.GetIdentifierName(), table_name); auto result = transaction.Query(query); auto rows = result->Count(); if (rows == 0) { @@ -245,7 +245,7 @@ string PostgresColumnsToSQL(const ColumnList &columns, const vectortype == ConstraintType::UNIQUE) { auto &pk = constraint->Cast(); - vector constraint_columns = pk.columns; + vector constraint_columns = pk.columns; if (pk.index.index != DConstants::INVALID_INDEX) { // no columns specified: single column constraint if (pk.is_primary_key) { @@ -259,7 +259,7 @@ string PostgresColumnsToSQL(const ColumnList &columns, const vector 0) { base += ", "; } - base += PostgresUtils::WriteIdentifier(pk.columns[i]); + base += PostgresUtils::WriteIdentifier(pk.columns[i].GetIdentifierName()); } extra_constraints.push_back(base + ")"); } @@ -286,11 +286,11 @@ string PostgresColumnsToSQL(const ColumnList &columns, const vector 0) { ss << ", "; } - ss << PostgresUtils::WriteIdentifier(column.Name()) << " "; + ss << PostgresUtils::WriteIdentifier(column.Name().GetIdentifierName()) << " "; ss << PostgresUtils::TypeToString(column.Type()); bool not_null = not_null_columns.find(column.Logical()) != not_null_columns.end(); bool is_single_key_pk = pk_columns.find(column.Logical()) != pk_columns.end(); - bool is_multi_key_pk = multi_key_pks.find(column.Name()) != multi_key_pks.end(); + bool is_multi_key_pk = multi_key_pks.find(column.Name().GetIdentifierName()) != multi_key_pks.end(); bool is_unique = unique_columns.find(column.Logical()) != unique_columns.end(); if (not_null && !is_single_key_pk && !is_multi_key_pk) { // NOT NULL but not a primary key column @@ -332,10 +332,10 @@ string GetPostgresCreateTable(CreateTableInfo &info) { ss << "IF NOT EXISTS "; } if (!info.schema.empty()) { - ss << PostgresUtils::WriteIdentifier(info.schema); + ss << PostgresUtils::WriteIdentifier(info.schema.GetIdentifierName()); ss << "."; } - ss << PostgresUtils::WriteIdentifier(info.table); + ss << PostgresUtils::WriteIdentifier(info.table.GetIdentifierName()); ss << PostgresColumnsToSQL(info.columns, info.constraints); ss << ";"; return ss.str(); @@ -350,8 +350,8 @@ optional_ptr PostgresTableSet::CreateTable(PostgresTransaction &tr string PostgresTableSet::GetAlterTablePrefix(const string &name, optional_ptr entry) { string sql = "ALTER TABLE "; - sql += PostgresUtils::WriteIdentifier(schema.name) + "."; - sql += PostgresUtils::WriteIdentifier(entry ? entry->name : name); + sql += PostgresUtils::WriteIdentifier(schema.name.GetIdentifierName()) + "."; + sql += PostgresUtils::WriteIdentifier(entry ? entry->name.GetIdentifierName() : name); return sql; } @@ -360,7 +360,7 @@ string PostgresTableSet::GetAlterTableColumnName(const string &name, optional_pt return name; } auto &table = entry->Cast(); - string column_name = name; + Identifier column_name = Identifier(name); auto column_index = table.GetColumnIndex(column_name, true); if (!column_index.IsValid()) { return name; @@ -375,31 +375,31 @@ string PostgresTableSet::GetAlterTablePrefix(ClientContext &context, PostgresTra } void PostgresTableSet::AlterTable(ClientContext &context, PostgresTransaction &transaction, RenameTableInfo &info) { - string sql = GetAlterTablePrefix(context, transaction, info.name); + string sql = GetAlterTablePrefix(context, transaction, info.name.GetIdentifierName()); sql += " RENAME TO "; - sql += PostgresUtils::WriteIdentifier(info.new_table_name); + sql += PostgresUtils::WriteIdentifier(info.new_table_name.GetIdentifierName()); transaction.Query(sql); } void PostgresTableSet::AlterTable(ClientContext &context, PostgresTransaction &transaction, RenameColumnInfo &info) { - auto entry = GetEntry(context, transaction, info.name); - string sql = GetAlterTablePrefix(info.name, entry); + auto entry = GetEntry(context, transaction, info.name.GetIdentifierName()); + string sql = GetAlterTablePrefix(info.name.GetIdentifierName(), entry); sql += " RENAME COLUMN "; - string column_name = GetAlterTableColumnName(info.old_name, entry); + string column_name = GetAlterTableColumnName(info.old_name.GetIdentifierName(), entry); sql += PostgresUtils::WriteIdentifier(column_name); sql += " TO "; - sql += PostgresUtils::WriteIdentifier(info.new_name); + sql += PostgresUtils::WriteIdentifier(info.new_name.GetIdentifierName()); transaction.Query(sql); } void PostgresTableSet::AlterTable(ClientContext &context, PostgresTransaction &transaction, AddColumnInfo &info) { - string sql = GetAlterTablePrefix(context, transaction, info.name); + string sql = GetAlterTablePrefix(context, transaction, info.name.GetIdentifierName()); sql += " ADD COLUMN "; if (info.if_column_not_exists) { sql += "IF NOT EXISTS "; } - sql += PostgresUtils::WriteIdentifier(info.new_column.Name()); + sql += PostgresUtils::WriteIdentifier(info.new_column.Name().GetIdentifierName()); sql += " "; sql += info.new_column.Type().ToString(); @@ -419,13 +419,13 @@ void PostgresTableSet::AlterTable(ClientContext &context, PostgresTransaction &t } void PostgresTableSet::AlterTable(ClientContext &context, PostgresTransaction &transaction, RemoveColumnInfo &info) { - auto entry = GetEntry(context, transaction, info.name); - string sql = GetAlterTablePrefix(info.name, entry); + auto entry = GetEntry(context, transaction, info.name.GetIdentifierName()); + string sql = GetAlterTablePrefix(info.name.GetIdentifierName(), entry); sql += " DROP COLUMN "; if (info.if_column_exists) { sql += "IF EXISTS "; } - string column_name = GetAlterTableColumnName(info.removed_column, entry); + string column_name = GetAlterTableColumnName(info.removed_column.GetIdentifierName(), entry); sql += PostgresUtils::WriteIdentifier(column_name); transaction.Query(sql); } diff --git a/src/storage/postgres_type_set.cpp b/src/storage/postgres_type_set.cpp index 451355592..cee52ac28 100644 --- a/src/storage/postgres_type_set.cpp +++ b/src/storage/postgres_type_set.cpp @@ -52,7 +52,7 @@ void PostgresTypeSet::CreateEnum(PostgresTransaction &transaction, PostgresResul PostgresType postgres_type; CreateTypeInfo info; postgres_type.oid = result.GetInt64(start_row, 1); - info.name = result.GetString(start_row, 2); + info.name = Identifier(result.GetString(start_row, 2)); // construct the enum idx_t enum_count = end_row - start_row; Vector duckdb_levels(LogicalType::VARCHAR, enum_count); @@ -60,7 +60,7 @@ void PostgresTypeSet::CreateEnum(PostgresTransaction &transaction, PostgresResul duckdb_levels.SetValue(enum_idx, result.GetString(start_row + enum_idx, 3)); } info.type = LogicalType::ENUM(duckdb_levels, enum_count); - info.type.SetAlias(info.name); + info.type.SetAlias(info.name.GetIdentifierName()); auto type_entry = make_shared_ptr(catalog, schema, info, postgres_type); CreateEntry(transaction, std::move(type_entry)); } @@ -114,7 +114,7 @@ void PostgresTypeSet::CreateCompositeType(PostgresTransaction &transaction, Post PostgresType postgres_type; CreateTypeInfo info; postgres_type.oid = result.GetInt64(start_row, 1); - info.name = result.GetString(start_row, 2); + info.name = Identifier(result.GetString(start_row, 2)); child_list_t child_types; for (idx_t row = start_row; row < end_row; row++) { @@ -123,12 +123,12 @@ void PostgresTypeSet::CreateCompositeType(PostgresTransaction &transaction, Post type_data.type_name = result.GetString(row, 4); type_data.type_schema = result.GetString(row, 5); PostgresType child_type; - child_types.push_back( - make_pair(type_name, PostgresUtils::TypeToLogicalType(&transaction, &schema, type_data, child_type))); + child_types.push_back(make_pair( + Identifier(type_name), PostgresUtils::TypeToLogicalType(&transaction, &schema, type_data, child_type))); postgres_type.children.push_back(std::move(child_type)); } info.type = LogicalType::STRUCT(std::move(child_types)); - info.type.SetAlias(info.name); + info.type.SetAlias(info.name.GetIdentifierName()); auto type_entry = make_shared_ptr(catalog, schema, info, postgres_type); CreateEntry(transaction, std::move(type_entry)); } @@ -165,7 +165,7 @@ void PostgresTypeSet::LoadEntries(ClientContext &context, PostgresTransaction &t string GetCreateTypeSQL(CreateTypeInfo &info) { string sql = "CREATE TYPE "; - sql += PostgresUtils::WriteIdentifier(info.name); + sql += PostgresUtils::WriteIdentifier(info.name.GetIdentifierName()); sql += " AS "; switch (info.type.id()) { case LogicalTypeId::ENUM: { @@ -188,7 +188,7 @@ string GetCreateTypeSQL(CreateTypeInfo &info) { if (c > 0) { sql += ", "; } - sql += PostgresUtils::WriteIdentifier(StructType::GetChildName(info.type, c)); + sql += PostgresUtils::WriteIdentifier(StructType::GetChildName(info.type, c).GetIdentifierName()); sql += " "; sql += PostgresUtils::TypeToString(StructType::GetChildType(info.type, c)); } @@ -206,7 +206,7 @@ optional_ptr PostgresTypeSet::CreateType(PostgresTransaction &tran auto create_sql = GetCreateTypeSQL(info); conn.Execute(transaction.GetContext(), create_sql); - info.type.SetAlias(info.name); + info.type.SetAlias(info.name.GetIdentifierName()); auto pg_type = PostgresUtils::CreateEmptyPostgresType(info.type); auto type_entry = make_shared_ptr(catalog, schema, info, pg_type); return CreateEntry(transaction, std::move(type_entry)); diff --git a/src/storage/postgres_update.cpp b/src/storage/postgres_update.cpp index 95a3ad8de..49c47e00c 100644 --- a/src/storage/postgres_update.cpp +++ b/src/storage/postgres_update.cpp @@ -61,8 +61,8 @@ string CreateUpdateTable(const string &name, PostgresTableEntry &table, const ve string GetUpdateSQL(const string &name, PostgresTableEntry &table, const vector &index) { string result; result = "UPDATE "; - result += PostgresUtils::WriteIdentifier(table.schema.name) + "."; - result += PostgresUtils::WriteIdentifier(table.name); + result += PostgresUtils::WriteIdentifier(table.schema.name.GetIdentifierName()) + "."; + result += PostgresUtils::WriteIdentifier(table.name.GetIdentifierName()); result += " SET "; for (idx_t i = 0; i < index.size(); i++) { if (i > 0) { @@ -77,7 +77,7 @@ string GetUpdateSQL(const string &name, PostgresTableEntry &table, const vector< } result += " FROM " + PostgresUtils::QuotePostgresIdentifier(name); result += " WHERE "; - result += PostgresUtils::WriteIdentifier(table.name); + result += PostgresUtils::WriteIdentifier(table.name.GetIdentifierName()); result += ".ctid=__page_id_string::TID"; return result; } @@ -196,7 +196,7 @@ string PostgresUpdate::GetName() const { InsertionOrderPreservingMap PostgresUpdate::ParamsToString() const { InsertionOrderPreservingMap result; - result["Table Name"] = table.name; + result["Table Name"] = table.name.GetIdentifierName(); return result; }