Skip to content

Commit

Permalink
Fix #242: correctly reset varchar chunk when casting data in CopyChunk
Browse files Browse the repository at this point in the history
  • Loading branch information
Mytherin committed Sep 3, 2024
1 parent b6dda6c commit 018aabb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
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

0 comments on commit 018aabb

Please sign in to comment.