Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #242: correctly reset varchar chunk when casting data in CopyChunk #254

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/postgres_copy_to.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ void PostgresConnection::CopyChunk(ClientContext &context, PostgresCopyState &st
varchar_types.push_back(LogicalType::VARCHAR);
}
varchar_chunk.Initialize(Allocator::DefaultAllocator(), varchar_types);
} else {
varchar_chunk.Reset();
}
D_ASSERT(chunk.ColumnCount() == varchar_chunk.ColumnCount());
// for text format cast to varchar first
Expand Down
32 changes: 32 additions & 0 deletions test/sql/storage/attach_varchar_list_nulls.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# name: test/sql/storage/attach_varchar_list_nulls.test
# description: Test inserting/querying VARCHAR lists with NULL values
# 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
CREATE OR REPLACE TABLE s.varchar_list_big(i BIGINT, v VARCHAR[]);

statement ok
CREATE TABLE tbl AS SELECT CASE WHEN i<1000 THEN NULL ELSE i END i, case when i<1000 then null else [i] end v FROM range(4000) t(i);

query IIII
select min(len(v)), max(len(v)), sum(len(v)), count(*) from tbl;
----
1 1 3000 4000

statement ok
INSERT INTo s.varchar_list_big FROM tbl

query IIII
select min(len(v)), max(len(v)), sum(len(v)), count(*) from s.varchar_list_big;
----
1 1 3000 4000
Loading