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

相关推荐
SelectDB2 小时前
为什么 JSON 正在成为分析数据库新的竞争点?
数据库·json·agent
ClouGence3 小时前
开源数据库管理工具 CloudDM 4.2.0 发布,新增 GoldenDB、KingbaseES 等数据源
数据库·dba·devops
发霉的馒头3 小时前
ORA-00845: MEMORY_TARGET not supported on this system的解决方法
数据库
草莓熊Lotso5 小时前
【Redis 初阶】Set 类型深度解析:去重集合的运算能力与实战场景
linux·网络·数据库·windows·redis·tcp/ip·缓存
煎饼皮皮侠7 小时前
【设计】设计一个web版的数据库管理平台后端(之五) --借鉴mybatis
数据库·mybatis
东风破_13 小时前
danci 2:创建的单词书到底存在哪里?从 Supabase 一路理解 ORM、Drizzle 和 RLS
数据库·后端·node.js
橙子家14 小时前
OSS 文件上传的几个风险点和解决方案
数据库
2601_9620664916 小时前
【Sql Server】Update中的From语句,以及常见更新操作方式
android·java·数据库
愤怒的苹果ext17 小时前
MySQL Shell备份恢复数据库
数据库·mysql·备份恢复·mysqlsh
数字新视界19 小时前
DCIM管理系统的技术架构与部署模式详解
数据库·物联网·数据中心·数据中心基础设施管理·dcim管理系统