LightDB - 支持quarter 函数[mysql兼容]

LightDB 从23.4版本开始支持 quarter 函数。

简介

quarter 函数用来确定日期对应的季度, 如
‘20231204’ 对应12月,也就是第四季度。

下面为mysql8.0中描述

Returns the quarter of the year for date, in the range 1 to 4, or NULL if date is NULL.

LightDB 目前支持只date 和 datetime(即timestamp)类型的入参。其他与mysql一致。

示例

lightdb@test_m=# select quarter(cast('20201001'as date));
 quarter 
---------
       4
(1 row)

lightdb@test_m=# select quarter(cast('20201001'as datetime));
 quarter 
---------
       4
(1 row)

lightdb@test_m=# select quarter(current_date());
 quarter 
---------
       4
(1 row)

lightdb@test_m=# select quarter('20201001');
ERROR:  function quarter(unknown) is not unique
LINE 1: select quarter('20201001');
               ^
HINT:  Could not choose a best candidate function. You might need to add explicit type casts.
lightdb@test_m=# select quarter(20201001);
ERROR:  function quarter(integer) does not exist
LINE 1: select quarter(20201001);
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
lightdb@test_m=# select quarter(20220501.1);
ERROR:  function quarter(numeric) does not exist
LINE 1: select quarter(20220501.1);
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
lightdb@test_m=# 

mysql 中效果

mysql> select quarter(20221212);
+-------------------+
| quarter(20221212) |
+-------------------+
|                 4 |
+-------------------+
1 row in set (0.01 sec)

mysql> select quarter(20220501.1);
+---------------------+
| quarter(20220501.1) |
+---------------------+
|                   2 |
+---------------------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+----------------------------------------------+
| Level   | Code | Message                                      |
+---------+------+----------------------------------------------+
| Warning | 1292 | Truncated incorrect date value: '20220501.1' |
+---------+------+----------------------------------------------+
1 row in set (0.00 sec)

mysql> select quarter('20220101');
+---------------------+
| quarter('20220101') |
+---------------------+
|                   1 |
+---------------------+
1 row in set (0.00 sec)

mysql> select quarter(cast('20201001'as date));
+----------------------------------+
| quarter(cast('20201001'as date)) |
+----------------------------------+
|                                4 |
+----------------------------------+
1 row in set (0.00 sec)

mysql> select quarter(cast('20201001'as datetime));
+--------------------------------------+
| quarter(cast('20201001'as datetime)) |
+--------------------------------------+
|                                    4 |
+--------------------------------------+
1 row in set (0.00 sec)

mysql> 

你可能感兴趣的:(lightdb,mysql,数据库,quarter,lightdb)