| 1 | #include "duckdb/function/scalar/date_functions.hpp" |
| 2 | |
| 3 | #include "duckdb/common/exception.hpp" |
| 4 | #include "duckdb/common/types/date.hpp" |
| 5 | #include "duckdb/common/types/timestamp.hpp" |
| 6 | #include "duckdb/common/vector_operations/vector_operations.hpp" |
| 7 | |
| 8 | using namespace std; |
| 9 | |
| 10 | namespace duckdb { |
| 11 | |
| 12 | static void current_time_function(DataChunk &input, ExpressionState &state, Vector &result) { |
| 13 | assert(input.column_count() == 0); |
| 14 | |
| 15 | auto val = Value::INTEGER(Timestamp::GetTime(Timestamp::GetCurrentTimestamp())); |
| 16 | result.Reference(val); |
| 17 | } |
| 18 | |
| 19 | static void current_date_function(DataChunk &input, ExpressionState &state, Vector &result) { |
| 20 | assert(input.column_count() == 0); |
| 21 | |
| 22 | auto val = Value::INTEGER(Timestamp::GetDate(Timestamp::GetCurrentTimestamp())); |
| 23 | result.Reference(val); |
| 24 | } |
| 25 | |
| 26 | static void current_timestamp_function(DataChunk &input, ExpressionState &state, Vector &result) { |
| 27 | assert(input.column_count() == 0); |
| 28 | |
| 29 | auto val = Value::TIMESTAMP(Timestamp::GetCurrentTimestamp()); |
| 30 | result.Reference(val); |
| 31 | } |
| 32 | |
| 33 | void CurrentTimeFun::RegisterFunction(BuiltinFunctions &set) { |
| 34 | set.AddFunction(ScalarFunction("current_time" , {}, SQLType::TIME, current_time_function)); |
| 35 | } |
| 36 | |
| 37 | void CurrentDateFun::RegisterFunction(BuiltinFunctions &set) { |
| 38 | set.AddFunction(ScalarFunction("current_date" , {}, SQLType::DATE, current_date_function)); |
| 39 | } |
| 40 | |
| 41 | void CurrentTimestampFun::RegisterFunction(BuiltinFunctions &set) { |
| 42 | set.AddFunction({"now" , "current_timestamp" }, ScalarFunction({}, SQLType::TIMESTAMP, current_timestamp_function)); |
| 43 | } |
| 44 | |
| 45 | } // namespace duckdb |
| 46 | |