json-extract sqlite format

天涯浪子 提交于 2020-01-16 19:34:31

问题


I used the following command SELECT json_extract(data,'$.address') FROM data;

and output as CSV file.

Output in CSV file is

enter image description here

Field (column) in CSV file is saved as 2 lines for 1 field (column).

Eg-

"71 CHOA CHU KANG LOOP

NORTHVALE"

How could I save field(column) as 1 line ?

That is I don't want to include new line character in filed(column).

Eg-

"71 CHOA CHU KANG LOOP NORTHVALE"

Thanks.


回答1:


Just replace the new line character:

select replace(json_extract(data,'$.address'), char(10), '') from data;

This will catch the newline character ('\n'). If you want '\r' and '\r\n' too:

select replace(
    replace(json_extract(data,'$.address'), char(10), ''), 
    char(13),
    ''
) from data;


来源:https://stackoverflow.com/questions/59504087/json-extract-sqlite-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!