本文主要是介绍LightDB - 支持 curdate, current_date 函数[mysql兼容],希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
从23.4 版本开始, LightDB 支持mysql 的curdate, current_date 函数。
curdate, current_date
current_date 与 curdate相同, 都是用来获取当前时间,下面是mysql 中的介绍:
Returns the current date as a value in ‘YYYY-MM-DD’ or YYYYMMDD format, depending on whether the function is used in string or numeric context.
注意点
在LightDB 中使用这两个函数有几个需要注意的点:
- 返回值类型为date类型, 只能返回’YYYY-MM-DD’ 格式, 不能返回 YYYYMMDD format, 加法减法与mysql效果不同
- curdate() 不能参与乘法或除法
示例
lightdb:
lightdb@test_m=# select curdate();curdate
------------2023-12-06
(1 row)lightdb@test_m=# select current_date();current_date
--------------2023-12-06
(1 row)lightdb@test_m=# select curdate()+1;?column?
------------2023-12-07
(1 row)lightdb@test_m=# select curdate()/2;
ERROR: operator does not exist: date / integer
LINE 1: select curdate()/2;^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
lightdb@test_m=# select curdate()*2;
ERROR: operator does not exist: date * integer
LINE 1: select curdate()*2;^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
lightdb@test_m=# select curdate()-2;?column?
------------2023-12-04
(1 row)
mysql:
mysql> select curdate();
+------------+
| curdate() |
+------------+
| 2023-12-06 |
+------------+
1 row in set (0.00 sec)mysql> select current_date();
+----------------+
| current_date() |
+----------------+
| 2023-12-06 |
+----------------+
1 row in set (0.00 sec)mysql> select curdate()+1;
+-------------+
| curdate()+1 |
+-------------+
| 20231207 |
+-------------+
1 row in set (0.00 sec)mysql> select curdate()/2;
+---------------+
| curdate()/2 |
+---------------+
| 10115603.0000 |
+---------------+
1 row in set (0.00 sec)mysql> select curdate()*2;
+-------------+
| curdate()*2 |
+-------------+
| 40462412 |
+-------------+
1 row in set (0.00 sec)mysql> select curdate()-1;
+-------------+
| curdate()-1 |
+-------------+
| 20231205 |
+-------------+
1 row in set (0.00 sec)mysql>
这篇关于LightDB - 支持 curdate, current_date 函数[mysql兼容]的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!