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

相关推荐
weelinking1 天前
【产品】00_产品经理用Claude实现产品系列介绍
数据库·人工智能·sql·数据挖掘·github·产品经理
2301_803934611 天前
Go语言如何做网络爬虫_Go语言爬虫开发教程【指南】
jvm·数据库·python
秋91 天前
windows中安装redis
数据库·redis·缓存
Cosolar1 天前
万字详解:RAG 向量索引算法与向量数据库架构及实战
数据库·人工智能·算法·数据库架构·milvus
想唱rap1 天前
IO多路转接之poll
服务器·开发语言·数据库·c++
SeaTunnel1 天前
AI 让 SeaTunnel 读源码和调试过时了吗?
大数据·数据库·人工智能·apache·seatunnel·数据同步
凯瑟琳.奥古斯特1 天前
数据冗余与规范化的本质[数据库原理]
开发语言·数据库·职场和发展
_ku_ku_1 天前
数据库系统原理 · SQL 数据定义、更新及数据库编程 · 自学总结
数据库·oracle
Mortalbreeze1 天前
深度理解文件系统 ---- 从磁盘存储到内核存储
大数据·linux·数据库
2301_803934611 天前
MySQL 字段类型选择规范指南
jvm·数据库·python