GBase 8s
其他
问答

默认添加timestamp字段

发表于2023-08-08 10:08:00486次浏览3个评论

为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。

【GBase版本】:8s

【操作系统】:centos7

【CPU】:

【问题描述】*:GBase 8S  timestamp字段默认添加当前时间加上时分秒(如:2023-8-8 10:00:00)默认值关键字或者表达式是什么

评论

登录后才可以发表评论
用户头像
路路路发表于 2年前
timestamp是datetime year to second/fraction(N)的别名。
timestamp表示datetime year to second;
timestamp(N) (1<=N<=6)表示datetime year to fraction(N) (1<=N<=5),特别说明:timestamp(6)实际将转换成datetime year to fraction(5)。

示例
创建表
create table tab_ts
(
col1 timestamp,
col2 timestamp(3),
col3 timestamp(5),
col4 timestamp(6)
);
insert into tab_ts values(
current year to fraction(5),
current year to fraction(5),
current year to fraction(5),
current year to fraction(5)
);

查询数据
select * from tab_ts;

结果
col1 2022-04-13 14:49:34
col2 2022-04-13 14:49:34.000
col3 2022-04-13 14:49:34.00000
col4 2022-04-13 14:49:34.00000
用户头像
路路路发表于 2年前
第一种方法:
create table test_3 (id int ,c_date timestamp default current year to second)
第二种方法:
create table test_1 (id int ,c_date datetime year to second default current year to second)
最佳回答
流泪猫猫头发表于 4个月前
学习了