PostgreSql中的timestamp用法
来源:互联网 发布:java代码生成文件夹 编辑:程序博客网 时间:2024/06/08 06:52
备注:这里不准备详细介绍各种类型,请注意上面表格中的[ (p) ] ,这个是什么呢?这个是指时间的精度,
time, timestamp, 和 interval 类型都可以指定精度,精度的取值范围是 0 到 6, 下面通过具体
实验来体验下精度。
二 current_timestamp 实验
--2.1 查询 current_timestamp
now
-------------------------------
2012-06-07 14:00:02.412827+08
(1 row)
备注: current_timestamp 函数返回时间类型为 timestamp with time zone,故返回结果后面包括时区 +08 ,
以及精度 412827,那么如何去掉精度和时区呢?
--2.2 去掉精度
timestamptz
------------------------
2012-06-07 14:07:17+08
(1 row)
--2.3 去掉时区
timestamp
---------------------
2012-06-07 14:07:49
(1 row)
--2.4 也可以用 cast 函数类型转换
timestamp
---------------------
2012-06-07 14:14:55
(1 row)
--2.5 了解 [p] 的含义 skytf=> select current_timestamp(2)::timestamp without time zone;
timestamp
------------------------
2012-06-07 14:15:42.64
(1 row)
skytf=> select current_timestamp(6)::timestamp without time zone;
timestamp
----------------------------
2012-06-07 14:15:46.281422
(1 row)
备注:可见 [p] 是指时间类型小数点后面的精度,如果 p 指定 2,则精度为2,如果 p 指定 6
则精度为 6; 所以在定义表的时候就应该事先定义 timestamp 时间类型的精度。
三 创建表测试,定义时间类型精度为0
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "test_p_pkey" for table "test_p"
CREATE TABLE
skytf=> \d test_p
Table "skytf.test_p"
Column | Type | Modifiers
-------------+--------------------------------+-----------
id | integer | not null
create_time | timestamp(0) without time zone |
Indexes:
"test_p_pkey" PRIMARY KEY, btree (id)
skytf=> select current_timestamp;
now
-------------------------------
2012-06-07 14:18:31.683105+08
(1 row)
skytf=> insert into test_p values (1,current_timestamp);
INSERT 0 1
skytf=> select * from test_p;
id | create_time
----+---------------------
1 | 2012-06-07 14:19:02
(1 row)
- PostgreSql中的timestamp用法
- timestamp[] postgresql
- PostgreSQL: 浅谈 PostgreSQL 的 timestamp 类型
- postgresql timestamp的精度问题
- 浅谈 PostgreSQL 的 timestamp 类型
- 浅谈 PostgreSQL 的 timestamp 类型
- postgresql timestamp timestamptz 使用注意事项
- mysql timestamp 基本用法
- MYSQL timestamp用法
- timestamp一些用法转载
- PostgreSQL 数据类型手册【serial, timestamp,text....】
- PostgreSQL中timestamp相关的SQL语句
- Oracle中的TIMESTAMP类型
- java中的Timestamp
- PostgreSQL常规用法
- PostgreSQL函数用法
- postgresql PREPARE 用法
- postgresql hstore用法
- resin和eclipse整合(傻瓜式)
- openfire_服务器部署到centos上
- Windows内核之线程的调度,优先级,亲缘性
- hdu 2196 树形dp
- 关于黑帽SEO的16种常见操作手法解析
- PostgreSql中的timestamp用法
- qiaoranliqu
- Scala学习1——搭建环境
- thinkpad X240 安装Ubuntu14.04 系统并搭建android开发环境
- [转]逆向思维 向您洞开一个新世界 - 此文价值千万以上
- 为什么我们喜欢用 sigmoid 这类 S 型非线性变换?
- STM32学习之路-LCD(2)<LCD初始化>
- 最近从网上看了篇单例的文章,拿来记录一下
- 主题模型及其在文本情感分析中的应用