PostgreSQL timestamp类型说明

今天使用dbeaver添加时间字段发现可以选择

timestamp without time zone 和timestamp 两个

这个两个有什么区别吗

实际没有区别

测试如下:

sql 复制代码
test1=# create table testtbl(info timestamp,info1  timestamp without time zone);
CREATE TABLE
test1=# \d testtbl
                        Table "public.testtbl"
 Column |            Type             | Collation | Nullable | Default
--------+-----------------------------+-----------+----------+---------
 info   | timestamp without time zone |           |          |
 info1  | timestamp without time zone |           |          |

实际是一个

但是PostgreSQL的类型中只有timestamp,并没有timestamp without time zone.

使用\d testtbl命令显示为timestamp without time zone是因为\d元命令后台调用了format_type函数,其会将timestamp类型表示为timestamp without time zone 而已。

sql 复制代码
test1=# select oid from pg_type where typname='timestamp';
 oid
------
 1114
(1 row)

test1=# select oid from pg_type where typname='timestamp without time zone';
 oid
-----
(0 rows)

为什么使用timestamp without time zone作为字段类型也可以呢

是因为PostgreSQL在语法分析阶段就将其转换成了timestamp了。

具体可以查看

src/backend/parser/gram.y

相关推荐
十二同学啊9 小时前
向量数据库:从核心原理到 RAG 与 Java 实战
数据库
蓝速科技9 小时前
会议室门牌公告通知发布选型与落地指南丨蓝速科技
大数据·运维·数据库·人工智能·科技
一 乐12 小时前
二手交易平台|基于springboot + vue二手交易平台(源码+数据库+文档)
java·数据库·vue.js·spring boot·小程序
SelectDB12 小时前
同等资源下 Apache Doris 4.2 vs StarRocks 4.1.1:1TB SSB 与 TPC-H 性能实测
大数据·数据库·数据分析
这个DBA有点耶13 小时前
数据库集群与分布式架构:三条技术路线对比、金仓KES RAC实测数据与决策框架
数据库·程序员·架构
MayBaymax13 小时前
MongoDB 索引与事务
java·数据库·mongodb
SelectDB13 小时前
Doris vs ClickHouse:企业 OLAP 走向下一阶段,两种技术路线如何选择
大数据·数据库·数据分析
vx-程序开发13 小时前
【计算机毕设】django校园跑腿服务系统83141
java·数据库·vue.js·spring boot·spring·elasticsearch·django
一 乐13 小时前
养老院管理系统|基于springboot + vue养老院管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·毕业设计
这个DBA有点耶14 小时前
InnoDB页结构深入:页分裂、页合并、填充因子——B+树底层机制全解析
数据库·mysql·架构