如何在PostgreSQL的换行符上将值拆分为多行?

编程入门 行业动态 更新时间:2024-10-26 14:40:33
本文介绍了如何在PostgreSQL的换行符上将值拆分为多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个名为 BookInfo 的表,其结构如下:

I have have table named BookInfo with the following structure:

|id |book_name |description | -------------------------------- |1 |book 1 |harry | | | |potter | | | |Part 2 | |2 |... | |

如何拆分行( id = 1 )换行符上的多行中(这样 harry \n potter \n Part 2 将被分为3个不同的记录:

How could I split the row (id=1) into multiple rows on the newline character (so that harry \n potter \n Part 2 would be separated into 3 different records: harry, potter and Part 2 using a query?

要重申,结果集应如下所示:

To reiterate, the resultset would look something like this:

|id | description | ---------------------- |1 |harry | |2 |potter | |3 |Part 2 |

任何帮助将不胜感激,谢谢。

Any help will be much appreciated, thank you.

推荐答案

您在寻找 regexp_split_to_table():

www.postgresql/docs/9.2/ static / functions-string.html

select regexp_split_to_table('hello world', E'\\s+'); hello world (2 rows)

更多推荐

如何在PostgreSQL的换行符上将值拆分为多行?

本文发布于:2023-10-26 11:03:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529944.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上将   换行符   如何在   PostgreSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!