Skip to content

feat: support DATETIME as an alias of TIMESTAMP - #26975

Merged
alamb merged 3 commits into
apache:mainfrom
hozan23:sql-datetime-timestamp-alias
Nov 4, 2026
Merged

alamb merged 3 commits into
apache:mainfrom
hozan23:sql-datetime-timestamp-alias

Conversation

@hozan23

@hozan23 hozan23 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Planning DATETIME failed with "Unsupported SQL type" unless a TypePlanner handled it.

What changes are included in this PR?

DATETIME and DATETIME(p) are planned as TIMESTAMP without a time zone, with the same precisions and nanosecond default.

What is the testing strategy for this PR?

New sqllogictest cases in datetime/timestamps.slt. test_custom_type_plan now expects DATETIME to plan by default.

Are there any user-facing changes?

Yes, DATETIME is now supported without a TypePlanner. No API changes.

@github-actions github-actions Bot added documentation Improvements or additions to documentation sql SQL Planner sqllogictest SQL Logic Tests (.slt) labels Oct 31, 2026

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks -- makes sense to me

@nuno-faria

Copy link
Copy Markdown
Contributor

Does having this example still make sense https://datafusion.apache.org/library-user-guide/extending-sql.html#example-custom-datetime-type? Maybe we could add a note saying that it is now implemented.

@hozan23
hozan23 force-pushed the sql-datetime-timestamp-alias branch from 1fa1d5d to faeb42c Compare November 1, 2026 18:41
@hozan23

hozan23 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

@nuno-faria I’ve added the note to the code's comment, not sure if we should add something else.

@nuno-faria nuno-faria left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @hozan23, I just have a question about the test_custom_type_plan test.

#[test]
fn test_custom_type_plan() -> Result<()> {
let sql = "SELECT DATETIME '2001-01-01 18:00:00'";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this test now use a different type? Because right now the result is the same as the default.

Planning DATETIME failed with "Unsupported SQL type" unless a
TypePlanner handled it.

Plan DATETIME and DATETIME(p) as TIMESTAMP without a time zone, with
the same precisions and nanosecond default.
@hozan23
hozan23 force-pushed the sql-datetime-timestamp-alias branch from a62449d to 1d4cf3f Compare November 4, 2026 08:59
@hozan23

hozan23 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

@nuno-faria I have made the custom planner (The one that been used in that test) maps DATETIME to Timestamp(unit, "UTC") instead of the default behavior

@hozan23
hozan23 requested a review from nuno-faria November 4, 2026 09:09
@nuno-faria

Copy link
Copy Markdown
Contributor

Thanks @hozan23, LGTM.

@alamb
alamb added this pull request to the merge queue Nov 4, 2026
Merged via the queue into apache:main with commit aeba33f Nov 4, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation sql SQL Planner sqllogictest SQL Logic Tests (.slt) v57.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support DATETIME SQL type in the planner

3 participants