MySQL 查询中的类型检查
因此,我使用运行以下查询将表转储到 CSV 文件:
SELECT * INTO OUTFILE 'testout.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
FROM dbname.tblname;
这工作正常,但所有字段都用双引号引起来。我想得到它,以便在输出中只有 varchar (即字符串)字段被引号包围。有什么简单的方法可以做到这一点吗?它可能会以某种方式涉及查询中的类型检查字段,但我对如何处理这个问题没有丝毫线索。任何帮助将不胜感激。
So I'm using to run the following query to dump my table to a CSV file:
SELECT * INTO OUTFILE 'testout.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
FROM dbname.tblname;
This works fine, but all of the fields are being surrounded by double quotes. I'd like to get it so that only the varchar (i.e. string) fields are surrounded by quotes in the output. Is there any easy way to do this? It would probably involve type-checking fields in the query somehow, but I don't have the slightest clue for how to approach this. Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您有 OPTIONALLY ENCLOSED BY 时,它应该已经按照您的意愿进行操作:
您确定不是每列都有 varchar 列吗?
When you have OPTIONALLY ENCLOSED BY it should already do as you want:
Are you sure that you don't have varchar columns for every column?