xuzifu666 commented on code in PR #4306:
URL: https://github.com/apache/calcite/pull/4306#discussion_r2045894208


##########
core/src/main/java/org/apache/calcite/sql/dialect/MysqlSqlDialect.java:
##########
@@ -366,17 +369,39 @@ private static void unparseFloor(SqlWriter writer, 
SqlCall call) {
     case SECOND:
       format = "%Y-%m-%d %H:%i:%s";
       break;
+    case MILLISECOND:
+      needSubStr = true;
+      format = "%Y-%m-%d %H:%i:%s.%f";
+      substringLength = 23;

Review Comment:
   Hi @mihaibudiu , thanks for the suggestion, do you mean only use date_format 
to archive it? 
   According to my previous research, currently MySQL can only  extract 
microsecond by this way:
   ```
   SELECT microsecond(NOW(6));
   >953213
   ```
   
   but seem there is no other way to extract millisecond:
   ```
   SELECT MILLISECOND(NOW(6));
   >[42000]: FUNCTION test_db.MILLISECOND does not exist
   ```
   
   and seems no other way to get MILLISECOND directly.
   
   I also test trailing zeros in fractional part:
   ```
   select DATE_FORMAT(NOW(6), '%Y-%m-%d %H:%i:%s.000'); 
   >2025-04-16 10:44:35.000
   
   select DATE_FORMAT(NOW(6), '%Y-%m-%d %H:%i:%s.%f000'); 
   >2025-04-16 10:45:10.467580000
   ```
   %f can only get six digits because MySQL max precision is 6.
   But according as I know users just use this way(substr + dateformat) to get 
millisecond/microsecond as a universal solution in many real production 
practice.
   
   WDYT?
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to