Home GaussDB在导入数据时给定唯一主键id
Post
Cancel

GaussDB在导入数据时给定唯一主键id

在要导入数据的表中增加create_time字段,默认值设置为pg_systimestamp(),在从csv文件导入数据的时候会自动给create_time字段插入时间戳。然后将时间戳转为纯数字字符串即可。

1
2
3
SELECT REPLACE(EXTRACT(EPOCH FROM create_time::TIMESTAMP)::VARCHAR, '.', '') FROM test_table tt;

UPDATE test_table SET id = REPLACE(EXTRACT(EPOCH FROM create_time::TIMESTAMP)::VARCHAR, '.', '');
This post is licensed under CC BY 4.0 by the author.