Skip to content
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
1 change: 1 addition & 0 deletions extension/core_functions/function_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ static const StaticFunctionDefinition core_functions[] = {
DUCKDB_SCALAR_FUNCTION_SET(MakeDateFun),
DUCKDB_SCALAR_FUNCTION(MakeTimeFun),
DUCKDB_SCALAR_FUNCTION_SET(MakeTimestampFun),
DUCKDB_SCALAR_FUNCTION_SET(MakeTimestampMsFun),
DUCKDB_SCALAR_FUNCTION_SET(MakeTimestampNsFun),
DUCKDB_SCALAR_FUNCTION(MapFun),
DUCKDB_SCALAR_FUNCTION(MapConcatFun),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,16 @@ struct MakeTimestampFun {
static ScalarFunctionSet GetFunctions();
};

struct MakeTimestampMsFun {
static constexpr const char *Name = "make_timestamp_ms";
static constexpr const char *Parameters = "nanos";
static constexpr const char *Description = "The timestamp for the given microseconds since the epoch";
static constexpr const char *Example = "make_timestamp_ms(1732117793000000)";
static constexpr const char *Categories = "";

static ScalarFunctionSet GetFunctions();
};

struct MakeTimestampNsFun {
static constexpr const char *Name = "make_timestamp_ns";
static constexpr const char *Parameters = "nanos";
Expand Down
17 changes: 15 additions & 2 deletions extension/core_functions/scalar/date/date_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,13 @@ struct DatePart {
}

static void Inverse(DataChunk &input, ExpressionState &state, Vector &result) {
throw NotImplementedException("EPOCH_MS(MS) has been removed. Use MAKE_TIMESTAMP[TZ](MS * 1000) instead.");
D_ASSERT(input.ColumnCount() == 1);

UnaryExecutor::Execute<int64_t, timestamp_t>(input.data[0], result, input.size(), [&](int64_t input) {
// millisecond amounts provided to epoch_ms should never be considered infinite
// instead such values will just throw when converted to microseconds
return Timestamp::FromEpochMsPossiblyInfinite(input);
});
}
};

Expand Down Expand Up @@ -2117,13 +2123,20 @@ ScalarFunctionSet EpochMsFun::GetFunctions() {
operator_set.AddFunction(
ScalarFunction({LogicalType::TIMESTAMP_TZ}, LogicalType::BIGINT, tstz_func, nullptr, nullptr, tstz_stats));

// Legacy inverse BIGINT => TIMESTAMP
// Deprecated inverse BIGINT => TIMESTAMP
operator_set.AddFunction(
ScalarFunction({LogicalType::BIGINT}, LogicalType::TIMESTAMP, DatePart::EpochMillisOperator::Inverse));

return operator_set;
}

ScalarFunctionSet MakeTimestampMsFun::GetFunctions() {
ScalarFunctionSet operator_set("make_timestamp_ms");
operator_set.AddFunction(
ScalarFunction({LogicalType::BIGINT}, LogicalType::TIMESTAMP, DatePart::EpochMillisOperator::Inverse));
return operator_set;
}

ScalarFunctionSet NanosecondsFun::GetFunctions() {
using OP = DatePart::NanosecondsOperator;
using TR = int64_t;
Expand Down
7 changes: 7 additions & 0 deletions extension/core_functions/scalar/date/functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@
"example": "make_timestamp(1992, 9, 20, 13, 34, 27.123456)",
"type": "scalar_function_set"
},
{
"name": "make_timestamp_ms",
"parameters": "nanos",
"description": "The timestamp for the given microseconds since the epoch",
"example": "make_timestamp_ms(1732117793000000)",
"type": "scalar_function_set"
},
{
"name": "make_timestamp_ns",
"parameters": "nanos",
Expand Down
1 change: 0 additions & 1 deletion src/catalog/default/default_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "duckdb/parser/parsed_data/create_macro_info.hpp"
#include "duckdb/parser/expression/columnref_expression.hpp"
#include "duckdb/catalog/catalog_entry/scalar_macro_catalog_entry.hpp"
#include "duckdb/function/table_macro_function.hpp"

#include "duckdb/function/scalar_macro_function.hpp"

Expand Down
1 change: 1 addition & 0 deletions src/include/duckdb/main/extension_entries.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ static constexpr ExtensionFunctionEntry EXTENSION_FUNCTIONS[] = {
{"make_date", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY},
{"make_time", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY},
{"make_timestamp", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY},
{"make_timestamp_ms", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY},
{"make_timestamp_ns", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY},
{"make_timestamptz", "icu", CatalogType::SCALAR_FUNCTION_ENTRY},
{"map", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY},
Expand Down
16 changes: 16 additions & 0 deletions test/sql/function/timestamp/epoch.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ SELECT
1960-10-10 23:59:59.999
1960-10-11 23:59:59

# MS version for replacing epoch_ms(bigint)
query TTTTTT
SELECT
make_timestamp_ms(0) as epoch1,
make_timestamp_ms(1574802684123) as epoch2,
make_timestamp_ms(-291044928000) as epoch3,
make_timestamp_ms(-291081600000) as epoch4,
make_timestamp_ms(-291081600001) as epoch5,
make_timestamp_ms(-290995201000) as epoch6
----
1970-01-01 00:00:00
2019-11-26 21:11:24.123
1960-10-11 10:11:12
1960-10-11 00:00:00
1960-10-10 23:59:59.999
1960-10-11 23:59:59

query IIII
SELECT to_timestamp(0), to_timestamp(1), to_timestamp(1574802684), to_timestamp(-1)
Expand Down
10 changes: 0 additions & 10 deletions test/sql/function/timestamp/test_date_part.test
Original file line number Diff line number Diff line change
Expand Up @@ -755,16 +755,6 @@ NULL NULL
2022-01-01 00:00:41+00 1640995241000
infinity NULL

statement error
select epoch_ms(9223372036854775807)
----
Not implemented Error: EPOCH_MS(MS) has been removed. Use MAKE_TIMESTAMP[TZ](MS * 1000) instead.

statement error
select epoch_ms(-9223372036854775808)
----
Not implemented Error: EPOCH_MS(MS) has been removed. Use MAKE_TIMESTAMP[TZ](MS * 1000) instead.

query II
SELECT ts, epoch_ns(ts) FROM timestamps ORDER BY ALL;
----
Expand Down
Loading