【问题标题】:PgAdmin Exporting text column to csv filePgAdmin 将文本列导出到 csv 文件
【发布时间】:2021-03-05 13:36:39
【问题描述】:

我有一个包含 3 列的表格 - 类型、名称和代码。 code 列包含过程/函数源代码。 我已经使用PgAdmin 4 v5 中的Import/Export 选项将它导出到一个csv 文件,但是code 列不会粘在csv 文件中的单个单元格上。其中的数据分布在许多行和列中。 我检查了EncodingUTF8,它在导出其他表时工作正常。

其他设置:Format: csvEncoding: UTF8。没有更改任何其他设置

有人可以帮助如何正确导出它。

【问题讨论】:

  • 仅供参考,它是 pgAdmin4 v5,没有 pgAdmin 5。您设置导出时使用的设置在哪里?
  • @AdrianKlaver,谢谢,编辑了正确的版本并将设置添加到问题中。
  • csv的默认分隔符是',',我会改成'|'开始。
  • @AdrianKlaver,将分隔符更改为“|”使格式变得更糟。我提到的表的第 3 列(文本数据类型)包含函数/过程代码,其中有很多换行符,这似乎是罪魁祸首。因为我已经导出了很多表,但我根本没有发现任何问题。
  • "代码列不会粘在 csv 文件中的单个单元格上" 如果您按照为 csv 文件定义的方式定义“单元格”,几乎可以肯定会这样做。如果您不希望它采用那种格式,那么不要告诉它使用那种格式。您希望它“正确”导出,但没有提供任何关于您认为这意味着什么的线索。

标签: postgresql pgadmin pgadmin-4


【解决方案1】:

您所看到的解释:

CREATE TABLE public.csv_test (
    fld_1 character varying,
    fld_2 character varying,
    fld_3 character varying,
    fld_4 character varying
);

insert into csv_test values ('1', E'line with line end. \n  New line', 'test', 'dog');
insert into csv_test values ('2', E'line with line end. \n  New line', 'test', 'dog');
insert into csv_test values ('3', E'line with line end. \n  New line \n Another line', 'test2', 'cat');
insert into csv_test values ('4', E'line with line end. \n  New line \n \t Another line', 'test3', 'cat');

select * from csv_test ;
 fld_1 |         fld_2         | fld_3 | fld_4 
-------+-----------------------+-------+-------
 1     | line with line end.  +| test  | dog
       |   New line            |       | 
 2     | line with line end.  +| test  | dog
       |   New line            |       | 
 3     | line with line end.  +| test2 | cat
       |   New line           +|       | 
       |  Another line         |       | 
 4     | line with line end.  +| test3 | cat
       |   New line           +|       | 
       |          Another line |       | 

\copy csv_test to csv_test.csv with (format 'csv');
\copy csv_test to csv_test.txt;

--fld_2 has line ends and/or tabs so in CSV the data will wrap inside the quotes.
cat csv_test.csv 
1,"line with line end. 
  New line",test,dog
2,"line with line end. 
  New line",test,dog
3,"line with line end. 
  New line 
 Another line",test2,cat
4,"line with line end. 
  New line 
         Another line",test3,cat

-- In text format the line ends and tabs are shown and not wrapped.
cat csv_test.txt 
1       line with line end. \n  New line        test    dog
2       line with line end. \n  New line        test    dog
3       line with line end. \n  New line \n Another line        test2   cat
4       line with line end. \n  New line \n \t Another line     test3   cat


【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-15
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-12
    相关资源
    最近更新 更多