Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #9755: TIMESTAMP_XX DOUBLE Parts #9769

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Issue #9755: TIMESTAMP_XX DOUBLE Parts
Handle the different precision timstamp types for the special
DOUBLE returning date parts (epoch and julian).

fixes: #9755
fixes duckdblabs/duckdb-internal#761
  • Loading branch information
Richard Wesley committed Nov 22, 2023
commit e280805320d2e5d4112a6d674e7b20d4172d1f53
6 changes: 6 additions & 0 deletions src/core_functions/scalar/date/date_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,9 @@ static unique_ptr<FunctionData> DatePartBind(ClientContext &context, ScalarFunct
bound_function.return_type = LogicalType::DOUBLE;
switch (arguments[0]->return_type.id()) {
case LogicalType::TIMESTAMP:
case LogicalType::TIMESTAMP_S:
case LogicalType::TIMESTAMP_MS:
case LogicalType::TIMESTAMP_NS:
bound_function.function = DatePart::UnaryFunction<timestamp_t, double, DatePart::JulianDayOperator>;
bound_function.statistics = DatePart::JulianDayOperator::template PropagateStatistics<timestamp_t>;
break;
Expand All @@ -1353,6 +1356,9 @@ static unique_ptr<FunctionData> DatePartBind(ClientContext &context, ScalarFunct
bound_function.return_type = LogicalType::DOUBLE;
switch (arguments[0]->return_type.id()) {
case LogicalType::TIMESTAMP:
case LogicalType::TIMESTAMP_S:
case LogicalType::TIMESTAMP_MS:
case LogicalType::TIMESTAMP_NS:
bound_function.function = DatePart::UnaryFunction<timestamp_t, double, DatePart::EpochOperator>;
bound_function.statistics = DatePart::EpochOperator::template PropagateStatistics<timestamp_t>;
break;
Expand Down
16 changes: 16 additions & 0 deletions test/sql/function/timestamp/test_date_part.test
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,22 @@ WHERE p <> f

endloop

# Cast injection for DOUBLE types
foreach tstype TIMESTAMP TIMESTAMP_S TIMESTAMP_MS TIMESTAMP_NS

query I
SELECT EXTRACT(EPOCH FROM ${tstype} '1992-09-20 11:30:00.0');
----
716988600.0

query I
SELECT EXTRACT(JULIAN FROM ${tstype} '1992-09-20 00:00:00.0');
----
2448886.0

endloop


#
# Structs
#
Expand Down
Loading