Skip to content

Conversation

@staticlibs
Copy link
Collaborator

This PR adds support for appending data to UNION columns. The tag (field name) of the union must be specified in beginUnion() call before appending the actual value.

Nested unions (or structs inside unions) are not supported.

Example:

CREATE TABLE tab1 (col1 INTEGER, col2 UNION(u1 INTEGER, u2 VARCHAR))
DuckDBAppender appender = conn.createAppender("tab1");

// append row with INTEGER value in UNION
appender
    .beginRow()
    .append(1)
    .beginUnion("u1")
    .append(42)
    .endUnion()
    .endRow();

// append row with VARCHAR value in UNION
appender
    .beginRow()
    .append(2)
    .beginUnion("u2")
    .append("foo")
    .endUnion()
    .endRow();

Testing: existing test is extended to cover UNIONs.

This PR adds support for appending data to `UNION` columns. The tag
(field name) of the union must be specified in `beginUnion()` call
before appending the actual value.

Nested unions (or structs inside unions) are not supported.

Example:

```sql
CREATE TABLE tab1 (col1 INTEGER, col2 UNION(u1 INTEGER, u2 VARCHAR))
```

```java
DuckDBAppender appender = conn.createAppender("tab1");

// append row with INTEGER value in UNION
appender
    .beginRow()
    .append(1)
    .beginUnion("u1")
    .append(42)
    .endUnion()
    .endRow();

// append row with VARCHAR value in UNION
appender
    .beginRow()
    .append(2)
    .beginUnion("u2")
    .append("foo")
    .endUnion()
    .endRow();
```

Testing: existing test is extended to cover `UNION`s.
@staticlibs staticlibs merged commit 6e2498e into duckdb:main Sep 15, 2025
@staticlibs staticlibs deleted the appender_union branch September 15, 2025 21:35
staticlibs added a commit to staticlibs/duckdb-java that referenced this pull request Sep 15, 2025
This is a backport of the PR duckdb#372 to `v1.4-andium` stable branch.

This PR adds support for appending data to `UNION` columns. The tag
(field name) of the union must be specified in `beginUnion()` call
before appending the actual value.

Nested unions (or structs inside unions) are not supported.

Example:

```sql
CREATE TABLE tab1 (col1 INTEGER, col2 UNION(u1 INTEGER, u2 VARCHAR))
```

```java
DuckDBAppender appender = conn.createAppender("tab1");

// append row with INTEGER value in UNION
appender
    .beginRow()
    .append(1)
    .beginUnion("u1")
    .append(42)
    .endUnion()
    .endRow();

// append row with VARCHAR value in UNION
appender
    .beginRow()
    .append(2)
    .beginUnion("u2")
    .append("foo")
    .endUnion()
    .endRow();
```

Testing: existing test is extended to cover `UNION`s.
staticlibs added a commit that referenced this pull request Sep 15, 2025
This is a backport of the PR #372 to `v1.4-andium` stable branch.

This PR adds support for appending data to `UNION` columns. The tag
(field name) of the union must be specified in `beginUnion()` call
before appending the actual value.

Nested unions (or structs inside unions) are not supported.

Example:

```sql
CREATE TABLE tab1 (col1 INTEGER, col2 UNION(u1 INTEGER, u2 VARCHAR))
```

```java
DuckDBAppender appender = conn.createAppender("tab1");

// append row with INTEGER value in UNION
appender
    .beginRow()
    .append(1)
    .beginUnion("u1")
    .append(42)
    .endUnion()
    .endRow();

// append row with VARCHAR value in UNION
appender
    .beginRow()
    .append(2)
    .beginUnion("u2")
    .append("foo")
    .endUnion()
    .endRow();
```

Testing: existing test is extended to cover `UNION`s.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant