diff --git a/duckdb b/duckdb index c8fa9aee..3240832c 160000 --- a/duckdb +++ b/duckdb @@ -1 +1 @@ -Subproject commit c8fa9aee7858909c625b5c3abcc3a257c5d9d934 +Subproject commit 3240832cddb955d4240cf2d3adcc053b77c88717 diff --git a/src/include/storage/postgres_catalog.hpp b/src/include/storage/postgres_catalog.hpp index 27719111..3faebf09 100644 --- a/src/include/storage/postgres_catalog.hpp +++ b/src/include/storage/postgres_catalog.hpp @@ -31,6 +31,9 @@ class PostgresCatalog : public Catalog { string GetCatalogType() override { return "postgres"; } + string GetDefaultSchema() const override { + return default_schema.empty() ? "public" : default_schema; + } optional_ptr CreateSchema(CatalogTransaction transaction, CreateSchemaInfo &info) override; diff --git a/src/storage/postgres_catalog.cpp b/src/storage/postgres_catalog.cpp index 345a79b5..13f46c5e 100644 --- a/src/storage/postgres_catalog.cpp +++ b/src/storage/postgres_catalog.cpp @@ -66,9 +66,6 @@ void PostgresCatalog::ScanSchemas(ClientContext &context, std::function PostgresCatalog::GetSchema(CatalogTransaction transaction, const string &schema_name, OnEntryNotFound if_not_found, QueryErrorContext error_context) { - if (schema_name == DEFAULT_SCHEMA) { - return GetSchema(transaction, default_schema, if_not_found, error_context); - } auto &postgres_transaction = PostgresTransaction::Get(transaction.GetContext(), *this); if (schema_name == "pg_temp") { return GetSchema(transaction, postgres_transaction.GetTemporarySchema(), if_not_found, error_context); diff --git a/test/other.sql b/test/other.sql index b13f7496..5406c854 100644 --- a/test/other.sql +++ b/test/other.sql @@ -164,3 +164,7 @@ INSERT INTO varchars_fixed_len VALUES ('hello'), ('world'), ('maxlength1'), ('he create table tbl_with_constraints(pk int primary key, c1 int not null, c2 int, c3 int not null); create table tbl_with_more_constraints(pk1 int, pk2 int, fk1 int references tbl_with_constraints(pk), primary key (pk1, pk2)); create table tbl_with_unique_constraints(pk int unique, c1 int not null, c2 int, c3 int not null, unique(c2, c3)); + +create schema main; +create table main.main_tbl(i int); +insert into main.main_tbl values (42), (NULL); diff --git a/test/sql/storage/attach_main_schema.test b/test/sql/storage/attach_main_schema.test new file mode 100644 index 00000000..e850937b --- /dev/null +++ b/test/sql/storage/attach_main_schema.test @@ -0,0 +1,28 @@ +# name: test/sql/storage/attach_main_schema.test +# description: Test usage of the main schema in Postgres +# group: [storage] + +require postgres_scanner + +require-env POSTGRES_TEST_DATABASE_AVAILABLE + +statement ok +PRAGMA enable_verification + +statement ok +ATTACH 'dbname=postgresscanner' AS s (TYPE POSTGRES) + +query I +SELECT * FROM s.main.main_tbl +---- +42 +NULL + +statement ok +USE s + +query I +SELECT * FROM main.main_tbl +---- +42 +NULL