Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql函数生成毫秒精度的时间戳作为BIGINT(13)_Sql_Mysql_Datetime_Timestamp - Fatal编程技术网

Mysql函数生成毫秒精度的时间戳作为BIGINT(13)

Mysql函数生成毫秒精度的时间戳作为BIGINT(13),sql,mysql,datetime,timestamp,Sql,Mysql,Datetime,Timestamp,我知道mysql不支持精确存储时间戳列 我的问题是:我是否可以编写一个mysql函数,将当前时间作为BIGINT(13)输出到毫秒精度 例如,as now()输出一个时间戳: mysql> select now(); +---------------------+ | now() | +---------------------+ | 2010-10-27 11:24:23 | +---------------------+ 我想写一个mysql函数,比如ts

我知道mysql不支持精确存储时间戳列

我的问题是:我是否可以编写一个mysql函数,将当前时间作为BIGINT(13)输出到毫秒精度

例如,as now()输出一个时间戳:

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2010-10-27 11:24:23 |
+---------------------+
我想写一个mysql函数,比如ts(),它输出一个bigint(13),例如

我希望这样做的原因是能够用函数ts()的值填充列的默认值

e、 g


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

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

mysql> select ts();
+---------------------+
| ts()               |
+---------------------+
| 1288172185517      |
+---------------------+
`MY_TIMESTAMP_COLUMN` BIGINT(13) DEFAULT ts(),