Skip to content

Commit

Permalink
Merge pull request #167 from Mytherin/issue160
Browse files Browse the repository at this point in the history
Fix #160: correctly account for schema name in DROP
  • Loading branch information
Mytherin authored Jan 17, 2024
2 parents bf0e87d + aa05e98 commit 5c1e9f8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/storage/postgres_catalog_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ void PostgresCatalogSet::DropEntry(ClientContext &context, DropInfo &info) {
if (info.if_not_found == OnEntryNotFound::RETURN_NULL) {
drop_query += " IF EXISTS ";
}
if (!info.schema.empty()) {
drop_query += KeywordHelper::WriteQuoted(info.schema, '"') + ".";
}
drop_query += KeywordHelper::WriteQuoted(info.name, '"');
if (info.cascade) {
drop_query += "CASCADE";
Expand Down
1 change: 1 addition & 0 deletions src/storage/postgres_schema_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void PostgresSchemaEntry::Scan(CatalogType type, const std::function<void(Catalo
}

void PostgresSchemaEntry::DropEntry(ClientContext &context, DropInfo &info) {
info.schema = name;
GetCatalogSet(info.type).DropEntry(context, info);
}

Expand Down
25 changes: 25 additions & 0 deletions test/sql/storage/attach_drop_table_in_schema.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# name: test/sql/storage/attach_drop_table_in_schema.test
# description: Test DROP TABLE within a schema
# group: [storage]

require postgres_scanner

require-env POSTGRES_TEST_DATABASE_AVAILABLE

statement ok
ATTACH 'dbname=postgresscanner' AS simple (TYPE POSTGRES)

statement ok
DROP SCHEMA IF EXISTS simple.new_schema CASCADE

statement ok
create schema simple.new_schema;

statement ok
create table simple.new_schema.newtable(i int);

statement ok
drop table simple.new_schema.newtable;

statement ok
drop schema simple.new_schema

0 comments on commit 5c1e9f8

Please sign in to comment.