Skip to content

Commit

Permalink
Merge pull request #253 from duckdb/issue250
Browse files Browse the repository at this point in the history
Fix #250 - always quote column names in CREATE TABLE to avoid Postgres' lowercasing them
  • Loading branch information
Mytherin authored Sep 3, 2024
2 parents b6dda6c + 54cafa2 commit ea103b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/storage/postgres_table_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ string PostgresColumnsToSQL(const ColumnList &columns, const vector<unique_ptr<C
if (column.Oid() > 0) {
ss << ", ";
}
ss << KeywordHelper::WriteOptionallyQuoted(column.Name()) << " ";
ss << KeywordHelper::WriteQuoted(column.Name(), '"') << " ";
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();
Expand Down
24 changes: 24 additions & 0 deletions test/sql/storage/attach_create_uppercase_names.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# name: test/sql/storage/attach_create_uppercase_names.test
# description: Test creating tables with uppercase column names
# 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)

statement ok
USE s

statement ok
CREATE OR REPLACE TABLE MyTable AS SELECT 42 MyColumn, 84 MySecondColumn

query II
SELECT MyColumn, MySecondColumn FROM MyTable
----
42 84

0 comments on commit ea103b4

Please sign in to comment.