timestamp和timestamptz是openGauss中用来表示日期和时间的数据类型,其中timestamptz是timestamp with time zone的别名,即带时区信息的timestamp。这两个数据类型在openGauss中存储时都占用8字节的存储空间。
下面以timestamp_example表为例,介绍timestamp类型上可以执行的一些常见操作
create table timestamp_example(
id integer primary key,
enter_time timestamp, --- 使用timestamp类型
leave_time timestamptz ---使用timestamptz类型
);
向数据表中插入数据
insert into timestamp_example values (100, '2022-06-07 11:30:12', '2022-06-07 11:32:02');
insert into timestamp_example values (101, '2022-06-07 11:31:12', '2022-06-07 11:42:02');
insert into timestamp_example values (102, '2022-06-07 11:40:15', '2022-06-07 11:52:00');
insert into timestamp_example values (103, '2022-06-07 12:40:15', '2022-06-07 12:46:00');
insert into timestamp_example values (104, '2022-06-07 12:47:15', '2022-06-07 12:55: