diff --git a/src/include/storage/postgres_catalog.hpp b/src/include/storage/postgres_catalog.hpp index b7635823..e7a5cc54 100644 --- a/src/include/storage/postgres_catalog.hpp +++ b/src/include/storage/postgres_catalog.hpp @@ -33,6 +33,9 @@ class PostgresCatalog : public Catalog { string GetCatalogType() override { return "postgres"; } + string GetDefaultSchema() const override { + return default_schema.empty() ? "public" : default_schema; + } static string GetConnectionString(ClientContext &context, const string &attach_path, string secret_name); diff --git a/src/storage/postgres_catalog.cpp b/src/storage/postgres_catalog.cpp index b7e482b1..0d9ce4b8 100644 --- a/src/storage/postgres_catalog.cpp +++ b/src/storage/postgres_catalog.cpp @@ -141,9 +141,6 @@ void PostgresCatalog::ScanSchemas(ClientContext &context, std::function PostgresCatalog::LookupSchema(CatalogTransaction transaction, const EntryLookupInfo &schema_lookup, OnEntryNotFound if_not_found) { auto schema_name = schema_lookup.GetEntryName(); - if (schema_name == DEFAULT_SCHEMA) { - schema_name = default_schema; - } auto &postgres_transaction = PostgresTransaction::Get(transaction.GetContext(), *this); if (schema_name == "pg_temp") { schema_name = postgres_transaction.GetTemporarySchema(); 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