我试图从CSV导入到Postgres,并在导入期间生成一个uuid uuid_generate_v4()来填充一个表。
Postgres版本: 14
Postgres表
key)
Psql导入
\copy "Country" (select uuid_generate_v4() as "id", "country_name", "country_ISO_code") FROM 'C:\Users\.......\data.csv' (format csv, header, delimiter ',')
但是,这会引发错误\copy: parse error at "as"
。
如何正确地指示psql使用uuid_generate_v4()
作为id列?
发布于 2021-12-04 04:48:06
不能从select语句复制“从”。您需要为主键定义一个默认值:
create table country
(
id uuid primary key default gen_random_uuid(),
country_name text not null,
country_iso_code text not null
);
然后告诉\copy
命令,输入文件只包含两列:
\copy country (country_name, country_iso_code) from 'data.csv' (format csv, header, delimiter ',')
https://stackoverflow.com/questions/70225264
复制相似问题