【问题标题】:How to convert a Mysql timestamp to sysdate(6) format(with milliseconds)?如何将 Mysql 时间戳转换为 sysdate(6) 格式(以毫秒为单位)?
【发布时间】:2016-04-29 01:24:22
【问题描述】:

我是 postgres 的新手,有时我一直在研究 Mysql。我需要将内容从 Mysql 表迁移到 Postgres 表。

我的 Postgres 表是这样的:

             Column             |            Type             |                                           Modifiers                                            
--------------------------------+-----------------------------+------------------------------------------------------------------------------------------------
 id                             | integer                     | 
 created_at                     | timestamp without time zone | not null default timezone('UTC'::text, now())
 updated_at                     | timestamp without time zone | not null default timezone('UTC'::text, now())
 key_classification             | character varying(2000)     | not null

我从 mysql 表中插入 created_at 和 updated_at 值,格式为“2014-09-04 23:40:14”。

当我在我的 postgres 表中插入一行时,默认时间戳采用“2016-01-22 17:44:53.342757”的形式,其中包括时间戳中的毫秒。

现在我需要在 mysql 时间戳格式中添加毫秒以匹配 postgres 表格式。

请帮忙将毫秒添加到时间戳中。

提前致谢!

【问题讨论】:

标签: mysql postgresql timestamp


【解决方案1】:

早上阿伦拉吉 我希望这会有所帮助?

我正在运行 Mysql/MariaDB

MariaDB [(none)]> SHOW VARIABLES LIKE "%version%";
+-------------------------+-----------------+
| Variable_name           | Value           |
+-------------------------+-----------------+
| innodb_version          | 5.6.25-73.1     |
| protocol_version        | 10              |
| slave_type_conversions  |                 |
| version                 | 10.0.21-MariaDB |
| version_comment         | MariaDB Server  |
| version_compile_machine | x86_64          |
| version_compile_os      | Linux           |
| version_malloc_library  | system          |
+-------------------------+-----------------+
8 rows in set (0.00 sec)

我指的是11.3.6 Fractional Seconds in Time Values 这是mysql 5.7版

运行示例

As mysql Admin 
mysql -u USERNAME -p

CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';

CREATE DATABASE test;

GRANT ALL ON test.* TO 'test'@'localhost';

退出,然后作为测试登录

mysql -u test -p

密码是test

然后

CREATE TABLE test.td6(ts6 timestamp(6));

INSERT INTO test.td6 VALUES ('2016-01-22 17:44:53.342757');

插入的值是你想插入mysql的时间戳格式。

一切顺利

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-17
    • 2011-05-07
    • 2017-05-28
    • 2020-06-24
    • 2015-04-29
    • 2021-08-20
    • 1970-01-01
    相关资源
    最近更新 更多