gpt4 book ai didi

postgresql - 类型 uuid : "" or "null" in PosgreSQL copy command 的输入语法无效

转载 作者:行者123 更新时间:2023-12-05 01:30:26 33 4
gpt4 key购买 nike

我已经从 SELECT 查询中创建了 csv-backup,现在正试图将其导入回数据库。但是我收到了这个错误:

COPY doc FROM '/tmp/doc.csv' DELIMITER ',' CSV HEADER;


ERROR: invalid input syntax for type uuid: "null"

如您所见,我的文件中的 "null" 为 NULL。

这发生在之前为空的可选字段上。

我找到了这个解决方案:https://stackoverflow.com/a/40428667/8443131

但它对我不起作用:

COPY doc FROM '/tmp/doc.csv' DELIMITER ',' CSV HEADER QUOTE '"null"' NULL '';

ERROR: COPY quote must be a single one-byte character

我如何导入这个文件?

UPD:我尝试用空引号替换空值。

命令已尝试:

COPY doc FROM '/tmp/null.csv' DELIMITER ',' CSV HEADER QUOTE '"' NULL '';

ERROR: invalid input syntax for type uuid: ""

文件的简短版本:

"id","removed","modified_at","root_id","parent_id","acl","properties","data","file_meta"
"f6a16ff7-4a31-11eb-be7b-8344edc8f36b","false","2021-01-04 00:00:12.347988","","","IS_PUBLIC","","",""
"2fdd0b8b-4a70-11eb-99fd-ad786a821574","false","2021-01-04 00:00:06.87298","","","IS_PUBLIC","","",""
"2c6d5fd1-4a70-11eb-99fd-ad786a821574","false","2021-01-04 00:00:07.536212","","","IS_PUBLIC","","",""
"fd645c21-4a6f-11eb-99fd-ad786a821574","false","2021-01-04 00:00:11.892367","","","IS_PUBLIC","","",""
"35c1fc53-4a70-11eb-99fd-ad786a821574","false","2021-01-04 00:00:05.517109","","","IS_PUBLIC","","",""
"35d165a4-4a70-11eb-99fd-ad786a821574","false","2021-01-04 00:00:01.72546","","","IS_PUBLIC","","",""
"fd40806d-4a6f-11eb-99fd-ad786a821574","false","2021-01-04 00:00:09.173726","","","IS_PUBLIC","","",""
"30ba4b45-4a70-11eb-99fd-ad786a821574","false","2021-01-04 00:00:04.655073","","","IS_PUBLIC","","",""

创建表:


-- Dumped from database version 13.0 (Debian 13.0-1.pgdg100+1)
-- Dumped by pg_dump version 13.0 (Debian 13.0-1.pgdg100+1)



CREATE TABLE public.doc (
id uuid NOT NULL,
removed boolean,
modified_at timestamp without time zone,
root_id uuid,
parent_id uuid,
acl jsonb,
properties jsonb,
data jsonb,
file_meta jsonb
);



ALTER TABLE ONLY public.doc
ADD CONSTRAINT doc_pkey PRIMARY KEY (id);

ALTER TABLE ONLY public.doc
ADD CONSTRAINT fk_document_entity FOREIGN KEY (id) REFERENCES public.main_table(id);

ALTER TABLE ONLY public.doc
ADD CONSTRAINT fk_document_parent FOREIGN KEY (parent_id) REFERENCES public.doc(id);

最佳答案

我用以下内容重现了您的情况,假设第二列是 boolean,第三列是 timestamp

create table test (col1 varchar, col2 boolean, col3 timestamp, col4 varchar, col5 varchar, col6 varchar, col7 varchar, col8 varchar, col9 varchar)                                  ;                                                                                               

如果我现在使用

copy test from STDIN delimiter ',' CSV QUOTE '"' NULL 'null';

并传递你提到的字符串

"f6a16ff7-4a31-11eb-be7b-8344edc8f36b","false","2021-01-04 00:00:12.347988","null","null","IS_PUBLIC","null","null","null"

数据解析正确

COPY 1

表格的输出看起来是正确的。

defaultdb=> select * from test;
col1 | col2 | col3 | col4 | col5 | col6 | col7 | col8 | col9
--------------------------------------+------+----------------------------+------+------+-----------+------+------+------
f6a16ff7-4a31-11eb-be7b-8344edc8f36b | f | 2021-01-04 00:00:12.347988 | null | null | IS_PUBLIC | null | null | null
(1 row)

关于postgresql - 类型 uuid : "" or "null" in PosgreSQL copy command 的输入语法无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67006034/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com