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

相关推荐
岳麓丹枫001几秒前
PgBouncer 从原理到实践
postgresql
油丶酸萝卜别吃3 分钟前
Redis 布隆过滤器快速实现
数据库·redis·缓存
深念Y4 分钟前
stable-diffusion.cpp 的 FLUX.2 Klein 9B 分步
java·前端·数据库
whn19777 分钟前
oracle 的ora-19633处理
数据库·oracle
小弥儿16 分钟前
Firecrawl:把整个网页变成 AI 可查询的数据库
数据库·人工智能·学习
swordbob24 分钟前
mysql数据库,明明有索引为啥不用
数据库·mysql
晴天¥1 小时前
Oracle ASM、ACFS、FLEX ASM三者之间的关系?
数据库·oracle
Leon-Ning Liu1 小时前
Oracle GoldenGate Replicat Abend:Key Column Missing 根因分析与修复
数据库·oracle
IvorySQL11 小时前
PostgreSQL 日报 | JOIN 与外键优化(8 月 9 日)
数据库·postgresql
ltl11 小时前
自治数据库十年回顾:Peloton、NoisePage、OtterTune 到云原生 auto-tuning
数据库