Skip to content

[Python] Enable rel[name] and rel.name syntax for struct fields#6988

Merged
Mytherin merged 4 commits intoduckdb:masterfrom
Tishj:python_getattr_struct
Apr 7, 2023
Merged

[Python] Enable rel[name] and rel.name syntax for struct fields#6988
Mytherin merged 4 commits intoduckdb:masterfrom
Tishj:python_getattr_struct

Conversation

@Tishj
Copy link
Contributor

@Tishj Tishj commented Apr 6, 2023

This PR extends #6624

Previously this already worked for column names:

import duckdb

duckdb.sql("""
    create table t as select {'a': 5, 'b': 'test'} as a, 'other' as c2
""")
rel = duckdb.table('a')
rel
"""
┌──────────────────────────────┬─────────┐
│              a               │   c2    │
│ struct(a integer, b varchar) │ varchar │
├──────────────────────────────┼─────────┤
│ {'a': 5, 'b': test}          │ other   │
└──────────────────────────────┴─────────┘
"""
rel.a
"""
┌──────────────────────────────┐
│              a               │
│ struct(a integer, b varchar) │
├──────────────────────────────┤
│ {'a': 5, 'b': test}          │
└──────────────────────────────┘
"""

This now produces the following behavior:

# This would produce the same result as `rel.a` before
rel.a.a
"""
┌───────┐
│   a   │
│ int32 │
├───────┤
│     5 │
└───────┘
"""

Copy link
Collaborator

@Mytherin Mytherin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! LGTM

@Tishj
Copy link
Contributor Author

Tishj commented Apr 7, 2023

This failure was related to #6983

@Mytherin Mytherin merged commit f84dabb into duckdb:master Apr 7, 2023
@Tishj Tishj deleted the python_getattr_struct branch November 7, 2025 16:15
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.

2 participants