我从 Heroku 托管的 SQL 数据库导出了用户表。导出看起来不错,但是当我尝试导入它时,我得到
ERROR: invalid input syntax for type uuid: "id"
这是 Heroku 站点使用的命令:
\copy users FROM ~/user_export.csv WITH (FORMAT CSV);
编辑: 我没有包括这个,但错误还包括:
CONTEXT: COPY users, line 1, column id: "id"
我已经完成了程序员数学运算并将其转换为从零开始的格式,但也许问题在于标题?
-- 答案:是的。啊。 /编辑
我在不同的地方发现了一些帖子,似乎涉及 JSON 字段,但 schema 相当简单,只使用了简单的对象:
Table "public.users"
Column | Type | Collation | Nullable | Default
------------------+--------------------------+-----------+----------+---------------------
id | uuid | | not null |
name | text | | not null |
username | text | | not null |
password_hash | text | | not null |
created_at | timestamp with time zone | | |
updated_at | timestamp with time zone | | |
tournament_id | uuid | | |
background | text | | |
as_player | boolean | | |
as_streamer | boolean | | |
administrator | administrator | | not null | 'no'::administrator
creator | boolean | | not null | false
creator_approved | boolean | | not null | true
Indexes:
"users_pkey" PRIMARY KEY, btree (id)
"uq:users.username" UNIQUE CONSTRAINT, btree (username)
Referenced by:
TABLE "tokens" CONSTRAINT "tokens_userID_fkey" FOREIGN KEY ("userID") REFERENCES users(id) ON DELETE CASCADE
TABLE "tournament_player_pivot" CONSTRAINT "tournament_player_pivot_playerID_fkey" FOREIGN KEY ("playerID") REFERENCES users(id)
导出数据的表和我尝试导入的表具有相同的架构。我发现 UUID 字段有一个特定的单引号格式,但手动修改没有效果。
这里有什么问题?
这是使用测试用户导出文件的示例:
id,name,username,password_hash,created_at,updated_at,tournament_id,background,as_player,as_streamer,administrator,creator,creator_approved
ad5230b4-2377-4a8d-8725-d49cd78121af,z9,[email protected],$2b$12$97GXVp1p.nfke8L4EYK2Fuev9IE3k0WFAf4O3NvziYHjogFCAppO6,2022-05-07 06:03:44.020019+00,2022-05-07 06:03:44.020019+00,,,f,f,no,f,t
您实际上可以只指定第一行是带有“HEADER”的标题行
COPY wheat FROM 'wheat_crop_data.csv' DELIMITER ';' CSV HEADER