[英]Export psql results to csv with proper boolean values
I am currently obtaining a csv string from psql using copyManager in a java service.我目前正在使用 java 服务中的 copyManager 从 psql 获取 csv 字符串。
String selectQuery = "SELECT * FROM table";
copyManager.copyOut("COPY (" + selectQuery + ") TO STDOUT WITH CSV HEADER", csaString);
But in the resulting string, all boolean values are as 't'/'f'
.但在结果字符串中,所有布尔值都为
't'/'f'
。 How do I get the boolean values as 'true'
or 'false'
.如何将布尔值设为
'true'
或'false'
。 Is there some configuration I can provide to do this?我可以提供一些配置来做到这一点吗?
This table has a lot of columns, so if I used a case to change it, I will also have to specify all the other columns which I want to avoid.这个表有很多列,所以如果我用一个案例来改变它,我还必须指定我想要避免的所有其他列。
there's no configuration for that I'm afraid.恐怕没有配置。 The best you could do is casting boolean columns as text.
您能做的最好的事情是将布尔列转换为文本。 You will have to list columns of course...
您当然必须列出列...
example:例子:
db=# select *,is_dst::text from pg_timezone_names limit 1;
name | abbrev | utc_offset | is_dst | is_dst
----------------+--------+------------+--------+--------
Africa/Abidjan | GMT | 00:00:00 | f | false
(1 row)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.