GBase 8a
运维管理
文章

GBase 8a数据入库增加时间戳的方法

发表于2025-01-11 11:41:5723次浏览1个评论

1、示例表结构
gbase> show create table tt.td;
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                      |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| td    | CREATE TABLE "td" (
 "id" int(11) DEFAULT NULL,
 "t" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=EXPRESS DEFAULT CHARSET=utf8 TABLESPACE='sys_tablespace' |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (Elapsed: 00:00:00.00)
2、示例数据
[gbase@vm20 ~]$ cat 2.txt 
10000
20000
3、入库语句

gbase> load data infile 'ftp://gbase:gbase@192.168.1.20//home/gbase/2.txt' into table tt.td  FIELDS TERMINATED   BY '|' table_fields 'id';
Query OK, 2 rows affected (Elapsed: 00:00:00.41)
Task 524299 finished, Loaded 2 records, Skipped 0 records
4、查看入库数据
gbase> select * from tt.td;
+-------+---------------------+
| id    | t                   |
+-------+---------------------+
| 10000 | 2019-10-23 23:58:25 |
| 20000 | 2019-10-23 23:58:25 |
+-------+---------------------+
2 rows in set (Elapsed: 00:00:00.01)

5、注意事项
同一张表不可以对1个以上的timestamp字段设置默认值CURRENT_TIMESTAMP
gbase> alter table td add t1 timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
ERROR 1702 (HY000): gcluster table error: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause.

评论

登录后才可以发表评论
用户头像
柒柒天晴发表于 2个月前
闪闪发光