如何拆分String并将其作为新行插入到同一表中? [英] How to split String and insert it as new line in the same table?
本文介绍了如何拆分String并将其作为新行插入到同一表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表地址。
create table address(
id number,
city text,
street text,
house_number text);
有时候我得到城市=柏林,街道= xyz和房屋编号
而不是3,例如3-5或3-5-7。
some times i get city = Berlin, street = xyz and house_number instead 3 ,for example, 3-5 or 3-5-7.
在这种情况下,我希望拆分此数字并创建新的行,以便得到:
i want in this case to split this numbers and crate new line/s so i get :
id city street house_number
1. Berlin xyz 3
2. Berlin xyz 5
2. Berlin xyz 7
关于
安德烈
推荐答案
使用选择unnest(string_to_array(YOUR STRING,'-'));
它将将'3-5-7'
转换为:
it will convert '3-5-7'
to:
3
5
7
然后,您可以简单地运行将表中的行插入查询。
请参见 SQLFiddle 。
Then you can simply run a query that will insert the rows to your table. See SQLFiddle.
这篇关于如何拆分String并将其作为新行插入到同一表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文