Repository: duckdb/duckdb (2026-06-15T11:07:23Z)

Issue:
Error inserting into a STRUCT with a VARIANT field
### What happens?

There is a problem with running `INSERT`s into a table with a `STRUCT` that contains a `VARIANT` field. The same has worked in 1.5. Error looks similar to the one in duckdb/duckdb-fuzzer#4526.

### To Reproduce

```sql
CREATE TABLE tab1 (col1 INTEGER, col2 STRUCT(s1 INTEGER, s2 VARIANT));
INSERT INTO tab1 VALUES(41, row(42, 'foo'));
```
```
INTERNAL Error:
VectorBuffer does not support SetVectorType
```

### OS:

Linux

### DuckDB Version:

main

### DuckDB Client:

CLI

### Hardware:

_No response_

### Full Name:

Alex Kasko

### Affiliation:

Duck Labs

### Did you include all relevant configuration (e.g., CPU architecture, Linux distribution) to reproduce the issue?

- [x] Yes, I have

### Did you include all code required to reproduce the issue?

- [x] Yes, I have

### Did you include all relevant data sets for reproducing the issue?

Yes


Discussion:

Patch:
diff --git a/src/common/vector/shredded_vector.cpp b/src/common/vector/shredded_vector.cpp
index a42fb0c13e53..faee370f010d 100644
--- a/src/common/vector/shredded_vector.cpp
+++ b/src/common/vector/shredded_vector.cpp
@@ -35,6 +35,10 @@ string ShreddedVectorBuffer::ToString(const LogicalType &type, idx_t count) cons
 	return "Shredded: " + shredded.ToString() + ", Unshredded: " + unshredded.ToString();
 }
 
+void ShreddedVectorBuffer::SetVectorType(VectorType new_vector_type) {
+	throw InternalException("ShreddedVectorBuffer::SetVectorType is not implemented and shouldn't be reached");
+}
+
 Value ShreddedVectorBuffer::GetValue(const LogicalType &type, idx_t index) const {
 	// FIXME: this is extremely inefficient
 	auto &shredded = StructVector::GetEntries(*shredded_data)[1];
diff --git a/src/function/cast/struct_cast.cpp b/src/function/cast/struct_cast.cpp
index 0e26f4be8d85..b0950ad8604e 100644
--- a/src/function/cast/struct_cast.cpp
+++ b/src/function/cast/struct_cast.cpp
@@ -124,14 +124,6 @@ static bool StructToStructCast(Vector &source, Vector &result, idx_t count, Cast
 			ConstantVector::SetNull(target_vector, count_t(count));
 		}
 	}
-
-	if (source.GetVectorType() == VectorType::CONSTANT_VECTOR) {
-		result.SetVectorType(VectorType::CONSTANT_VECTOR);
-		FlatVector::SetSize(result, count);
-		ConstantVector::SetNull(result, ConstantVector::IsNull(source));
-		return all_converted;
-	}
-
 	FlatVector::CopyValidity(result, source, count);
 	FlatVector::SetSize(result, count);
 	result.Verify();
diff --git a/src/include/duckdb/common/vector/shredded_vector.hpp b/src/include/duckdb/common/vector/shredded_vector.hpp
index 03ef7b1401c5..43e0272ec14c 100644
--- a/src/include/duckdb/common/vector/shredded_vector.hpp
+++ b/src/include/duckdb/common/vector/shredded_vector.hpp
@@ -30,6 +30,7 @@ class ShreddedVectorBuffer : public VectorBuffer {
 	idx_t GetAllocationSize() const override;
 	string ToString(const LogicalType &type, idx_t count) const override;
 	Value GetValue(const LogicalType &type, idx_t index) const override;
+	void SetVectorType(VectorType new_vector_type) override;
 
 protected:
 	buffer_ptr<VectorBuffer> FlattenSliceInternal(const LogicalType &type, const SelectionVector &sel,


Test patch:
diff --git a/test/sql/storage/types/variant/struct_of_variant.test b/test/sql/storage/types/variant/struct_of_variant.test
index 90e9cb830039..346bc14659f4 100644
--- a/test/sql/storage/types/variant/struct_of_variant.test
+++ b/test/sql/storage/types/variant/struct_of_variant.test
@@ -25,6 +25,9 @@ INSERT INTO variant_list SELECT {
 	'f4': i % 2 == 0
 } from range(1000) t(i)
 
+statement ok
+INSERT INTO variant_list VALUES(row(3000, 'test', 'hello world', 42));
+
 statement ok
 checkpoint;
 
@@ -35,7 +38,7 @@ select
 	col.f2.a::INTEGER,
 	col.f2.b::VARCHAR,
 	col.f4
-from variant_list limit 10
+from variant_list order by col.f1 limit 10
 ----
 0	val0	true
 1	val1	false