加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在PostgreSQL中使用timestamp数据类型

发布时间:2020-12-13 16:40:06 所属栏目:百科 来源:网络整理
导读:参考自:https://www.postgresql.org/docs/10/static/functions-formatting.html To get three milliseconds,one must write 12.003 ,which the conversion treats as 12 + 0.003 = 12.003 seconds. 第一点:众所周知,timestamp数据类型最细粒度到微秒(us),


参考自:https://www.postgresql.org/docs/10/static/functions-formatting.html

  • To get three milliseconds,one must write 12.003,which the conversion treats as 12 + 0.003 = 12.003 seconds.


第一点:众所周知,timestamp数据类型最细粒度到微秒(us),也就是timestamp(6)
那么

postgres=# create table abc_s.test_lei (c1 timestamp(7));
WARNING:  TIMESTAMP(7) precision reduced to maximum allowed,6
第1行create table abc_s.test_lei (c1 timestamp(7));
                                     ^
WARNING:  TIMESTAMP(7) precision reduced to maximum allowed,6
CREATE TABLE
postgres=#

那么如上的语句虽然报错了,但是这个表还是create成功了,见下:

postgres=# d abc_s.test_lei
                        数据表 "abc_s.test_lei"
 栏位 |              类型              | Collation | Nullable | Default
------+--------------------------------+-----------+----------+---------
 c1   | timestamp(6) without time zone |           |          |


---->>>>可以看到,自动给变成6了。因为最大到6--微秒
postgres=#

第二点:
sql语句中想插入400毫秒,就要写:
insert into test_t1 values(to_timestamp('2049-11-22 21:21:21.4','YYYY-MM-DD HH24:MI:SS.MS'));

sql语句中想插入40毫秒,就要写:
insert into test_t1 values(to_timestamp('2049-11-22 21:21:21.04','YYYY-MM-DD HH24:MI:SS.MS'));

sql语句中想插入4毫秒,就要写:
insert into test_t1 values(to_timestamp('2049-11-22 21:21:21.004','YYYY-MM-DD HH24:MI:SS.MS'));
因为1000毫秒=1秒

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读