7

我有这样的数据:

Akhound,1,Akhoond,"{""Akhund"", ""Akhwan""}",0

pgAdmin 的导入拒绝了这一点。CSV 中的 text[] 需要采用什么格式?

我也试过这个:

Akhoond,1,Akhoond,"{Akhund, Akhwan}",0

这是表创建:

CREATE TABLE private."Titles"
(
  "Abbrev" text NOT NULL,
  "LangID" smallint NOT NULL REFERENCES private."Languages" ("LangID"),
  "Full" text NOT NULL,
  "Alt" text[],
  "Affix" bit
)
WITH (
  OIDS=FALSE
);

ALTER TABLE private."Titles" ADD PRIMARY KEY ("Abbrev", "LangID");

CREATE INDEX ix_titles_alt ON private."Titles" USING GIN ("Alt");

ALTER TABLE private."Titles"
  OWNER TO postgres;
4

1 回答 1

9

找出答案的最佳方法是创建一个包含所需值的表并COPY ... TO STDOUT查看:

craig=> CREATE TABLE copyarray(a text, b integer, c text[], d integer);
CREATE TABLE
craig=> insert into copyarray(a,b,c,d) values ('Akhoond',1,ARRAY['Akhund','Akhwan'],0);
INSERT 0 1
craig=> insert into copyarray(a,b,c,d) values ('Akhoond',1,ARRAY['blah with spaces','blah,with,commas''and"quotes'],0);
INSERT 0 1
craig=> \copy copyarray TO stdout WITH (FORMAT CSV)
Akhoond,1,"{Akhund,Akhwan}",0
Akhoond,1,"{""blah with spaces"",""blah,with,commas'and\""quotes""}",0

所以看起来"{Akhund,Akhwan}"还不错。请注意我添加的第二个示例,该示例显示了如何处理数组文本中的逗号、引号空格。

这适用于 psql\copy命令;如果它不适用于 PgAdmin-III,那么我建议使用psqland \copy

于 2013-04-16T10:54:00.200 回答