From 1f643ee3c6eaa25da3f90e879416bef785971fdf Mon Sep 17 00:00:00 2001 From: Mark Raasveldt Date: Tue, 28 Jan 2025 18:27:23 +0100 Subject: [PATCH 1/3] Fix #272: no longer treat main schema as a special schema (requires upstream DuckDB fixes) --- src/include/storage/postgres_catalog.hpp | 3 +++ src/storage/postgres_catalog.cpp | 3 --- test/other.sql | 4 ++++ test/sql/storage/attach_main_schema.test | 28 ++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 test/sql/storage/attach_main_schema.test 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 From 5c047522c79117c7ed992cfc94edced0e7d1bc92 Mon Sep 17 00:00:00 2001 From: Mark Raasveldt Date: Wed, 29 Jan 2025 09:51:51 +0100 Subject: [PATCH 2/3] Bump duckdb --- duckdb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/duckdb b/duckdb index c8fa9aee..aaa5443f 160000 --- a/duckdb +++ b/duckdb @@ -1 +1 @@ -Subproject commit c8fa9aee7858909c625b5c3abcc3a257c5d9d934 +Subproject commit aaa5443f2bdde371be543ba781485624c5fdaf21 From 27aeebc2c7ec2734c1bedc375735b1c63d49fa43 Mon Sep 17 00:00:00 2001 From: Mytherin Date: Tue, 4 Feb 2025 13:04:21 +0100 Subject: [PATCH 3/3] Bump duckdb again --- duckdb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/duckdb b/duckdb index aaa5443f..3240832c 160000 --- a/duckdb +++ b/duckdb @@ -1 +1 @@ -Subproject commit aaa5443f2bdde371be543ba781485624c5fdaf21 +Subproject commit 3240832cddb955d4240cf2d3adcc053b77c88717