【问题标题】:Mysql function to generate millisecond precision timestamp as a BIGINT(13)Mysql 函数生成毫秒精度时间戳作为 BIGINT(13)
【发布时间】:2011-05-01 05:42:42
【问题描述】:

我知道mysql不支持以millisecond精度存储时间戳列。

我的问题:有没有我可以编写的 mysql 函数将当前时间输出为 BIGINT(13) 到毫秒精度。

例如,作为 now() 输出时间戳:

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2010-10-27 11:24:23 |
+---------------------+

我想写一个 mysql 函数,比如输出 bigint(13) 的 ts(),例如

mysql> select ts();
+---------------------+
| ts()               |
+---------------------+
| 1288172185517      |
+---------------------+

我想要这个的原因是能够用函数 ts() 的值填充列的默认值

例如..g

`MY_TIMESTAMP_COLUMN` BIGINT(13) DEFAULT ts(),

【问题讨论】:

    标签: sql mysql datetime timestamp


    【解决方案1】:

    您发布的文章链接指的是此类功能的实现:

    http://bugs.mysql.com/bug.php?id=8523

    如果您用tv.tv_sec * 1000000 + tv.tv_usec 替换对sprinf 的调用,该函数将以自纪元以​​来的微秒数返回本地时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-20
      • 2011-12-30
      • 2015-11-06
      • 1970-01-01
      • 2014-10-21
      • 2020-03-18
      • 1970-01-01
      • 2023-03-17
      相关资源
      最近更新 更多