从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>