Skip to content

Conversation

@VaggelisD
Copy link
Collaborator

Fixes #6394

Although this is not properly documented, the following query is valid in DuckDB:

D select MAKE_DATE(DATE_PART(['year', 'month', 'day'], TODAY())) AS col;
┌────────────┐
│    col     │
│    date    │
├────────────┤
│ 2025-11-24 │
└────────────┘

This is because:

  • DATE_PART returns either an INT64 or a STRUCT of values, depending on the input expression:
D SELECT DATE_PART('day', TODAY()) AS integer, DATE_PART(['year', 'month', 'day'], TODAY()) AS strct;
┌─────────┬─────────────────────────────────────────────────────┐
│ integer │                        strct                        │
│  int64  │ struct("year" bigint, "month" bigint, "day" bigint) │
├─────────┼─────────────────────────────────────────────────────┤
│   24    │ {'year': 2025, 'month': 11, 'day': 24}              │
└─────────┴─────────────────────────────────────────────────────┘
  • MAKE_DATE accepts either INT64s or a STRUCT which encodes those kwargs

Note: To properly represent that in the AST we'd have to infer whether the MAKE_DATE expression evaluates to an INT64 or a STRUCT, but since this low ROI we instead store that in the first argument year.

Docs

DuckDB MAKE_DATE | DuckDB DATE_PART

Copy link
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

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

Should we just create a new arg named date_part_struct or something?

@VaggelisD
Copy link
Collaborator Author

Should we just create a new arg named date_part_struct or something?

Not sure whether it's straightforward, we could have columns representing either INT/STRUCT, DATE_PART representing either type etc. For instance:

D SELECT MAKE_DATE(col) FROM (SELECT 20416 col);
┌────────────────┐
│ make_date(col) │
│      date      │
├────────────────┤
│ 2025-11-24     │
└────────────────┘


D SELECT MAKE_DATE(col) FROM (SELECT {'year': 2025, 'month': 11, 'day': 24} AS col);
┌────────────────┐
│ make_date(col) │
│      date      │
├────────────────┤
│ 2025-11-24     │
└────────────────┘

@georgesittas
Copy link
Collaborator

georgesittas commented Nov 24, 2025

Ah, I wasn't aware that a single integer value works as well. Looks good then, ship it.

@VaggelisD VaggelisD merged commit 67f499d into main Nov 24, 2025
8 checks passed
@VaggelisD VaggelisD deleted the vaggelisd/duckdb_make_date branch November 24, 2025 15:18
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.

DuckDB dialect parse error: date_part

3 participants