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

相关推荐
Yolanda942 小时前
【IDEA】IDEA连接MongoDB数据库
数据库·mongodb·idea使用
FJW0208142 小时前
关系型数据库大王Mysql——SQL编程
数据库·sql·mysql
一 乐2 小时前
在线考试|基于springboot + vue在线考试系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·课程设计
yufuu982 小时前
Python数据库操作:SQLAlchemy ORM指南
jvm·数据库·python
heze092 小时前
sqli-labs-Less-26
数据库·mysql·网络安全
ahauedu2 小时前
在 MySQL 中设置 `max_allowed_packet` 参数的几种方法
数据库·mysql
DolphinScheduler社区2 小时前
深度探秘 Apache DolphinScheduler 数据库模式
数据库·开源·apache·开源社区·海豚调度·大数据工作流调度
砚边数影2 小时前
时序数据库InfluxDB迁移替换实测,运维成本显著优化
运维·数据库·时序数据库·kingbase·kingbasees·金仓数据库
Apple_羊先森2 小时前
ORACLE数据库巡检SQL脚本--1、检查表空间使用情况
数据库·sql·oracle