Skip to content

Could not convert object (DICT) to the desired target type (STRUCT()) in an UDF #14211

@bjornasm

Description

@bjornasm

What happens?

I try to make an UDF that returns a dict, however duckdb fails to retrieve and convert that dict to a struct.

To Reproduce

import duckdb
from duckdb.typing import *

con = duckdb.connect('test')
def return_dict():
    return {
    1: "one",
    "2": 2,
    "three": [1, 2, 3],
    False: True
}

con.create_function("return_dict", return_dict, [], dict())

Then I try to retrieve the dict:

con.sql("SELECT return_dict()").fetchall()
InvalidInputException: Invalid Input Error: We could not convert the object {1: 'one', '2': 2, 'three': [1, 2, 3], False: True} to the desired target type (STRUCT())

OS:

Windows 10 x64

DuckDB Version:

1.1.1

DuckDB Client:

Python

Hardware:

No response

Full Name:

Bjørnar Brende Smestad

Affiliation:

NTNU

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have not tested with any build

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

Yes

Did you include all code required to reproduce the issue?

  • Yes, I have

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

  • Yes, I have

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions