欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

怎么在PostgreSQL中使用timestamp数据类型?

程序员文章站 2022-03-08 23:03:58
to get three milliseconds, one must write 12.003, which the conversion treats as 12 + 0.003 = 12.00...

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成功了,见下:

第二点:

sql语句中想插入400毫秒,就要写:

sql语句中想插入40毫秒,就要写:

sql语句中想插入4毫秒,就要写:

因为1000毫秒=1秒