当前位置:网站首页>Introduction and example application of PostgreSQL string separator function (regexp\u split\u to\u table)
Introduction and example application of PostgreSQL string separator function (regexp\u split\u to\u table)
2022-06-22 22:41:00 【Southejor】
PostgreSQL String separator functions (regexp_split_to_table) Introduction and example application
In project development , Sometimes you will encounter the need to split column data by a certain character , This article introduces in detail postgre Database split characters (regexp_split_to_table) And practical project application .
PostgreSQL String separator functions
-- Split into arrays , Subscript values can be used
select (regexp_split_to_array('11,22,33',','))[2];
-- Split into virtual tables , It can be directly used as a normal table , Make a connection query , Add query criteria, etc
select re from regexp_split_to_table('11,22,33',',') re where re='11';
PostgreSQL String separator function example application
Actual project requirements
In our project , The number of institutions and universities should be counted and ranked according to certain conditions , Some data in the database table is marked with semicolons ( ; ) Spliced multiple institutional Universities ,
such as : Wuhan University ; Electric Power Research Institute of Hebei electric power company .
In this case , Direct statistics are wrong , You need to put the data in semicolons first ( ; ) Split into independent universities and institutions , Then count the quantity .
Actual data
Directly querying data is 1168 strip .

Split data
First use regexp_split_to_table Function to view the split data , After the split, the universities and institutions are 2797 strip .
SELECT
regexp_split_to_table( applicant, ';' ) AS inventor_
FROM
Table name
-- Query criteria have been omitted

Here is the split data , You can see , The same query criteria , The data has been split up , The correct results can only be obtained by statistical split data .
The practical application
In the project , We will query and count the split data as a virtual table .
The query execution process is : First, find the data that meets the requirements according to the query criteria , Then split the data , Finally, count the total number .
sql sentence
SELECT
regexp_split_to_table( applicant, ';' ) AS inventor_,
COUNT ( * )
FROM
Table name pt
WHERE
-- Query criteria have been omitted
GROUP BY
inventor_
ORDER BY
COUNT DESC
LIMIT 10
statistics 
边栏推荐
- Lua -- iterator, module, meta table
- SPA项目开发之动态树+数据表格+分页
- Basic MySQL database operations
- 【几何法视觉】4.2 分段线性变换
- Mysql database DML operation exercise
- Makefile:1860: recipe for target ‘cmake_ check_ build_ system‘ failed make: *** [cmake_check_build_syst
- [geometric vision] 4.2 piecewise linear transformation
- NiO copy file call getchannel method transferfrom()
- How to quickly build an enterprise knowledge base at low cost?
- A group of K overturned linked lists [disassembly / overturning / assembly of linked lists]
猜你喜欢
![[ROS introduction] cmakelist Txt and packages XML interpretation](/img/37/24ce4be244ea56c2c84342492fccd4.png)
[ROS introduction] cmakelist Txt and packages XML interpretation
![[geometric vision] 4.2 piecewise linear transformation](/img/1e/a810f4d7e9a6a34647b5cb56fdde67.png)
[geometric vision] 4.2 piecewise linear transformation
![[GWCTF 2019]mypassword XSS](/img/26/3611fd5aae21ea004dcfcc2c623328.png)
[GWCTF 2019]mypassword XSS

新捷途X70S上市8.79万起,空间安全越级,不愧是网红国民大7座SUV

Huawei cloud recruits partners in the field of industrial intelligence to provide strong support + commercial realization
![Total number of combinations [standard backtracking + backtracking techniques -- reducing stack depth]](/img/88/3a07589bf8edab618139b1bf1680e8.png)
Total number of combinations [standard backtracking + backtracking techniques -- reducing stack depth]

SPA项目开发之首页导航+左侧菜单

British teddy bear joins the pubg mobile game

Query es page subscript exceeds 10000

The mental process and understanding of visual project code design
随机推荐
【ROS】ROSmsg cakin_make编译错误
The relationship between derivative and differential of function
Atcoder abc256 full problem solution (interval merging template, matrix fast power optimization DP, line segment tree...)
组合总数[标准回溯 + 回溯技巧--降低栈深度]
Experiment 4 operation comparison between NoSQL and relational database
MySQL functions
Crud+ form verification for spa project development
Reasons for the failure of digital transformation and the way to success
Talk about SQL profile again: can I fix the execution plan?
[interpretation of the paper] sort out the papers on the vision based autonomous landing platform of UAV
Palindromes (simple version)
Kdd'22 | Ali: fine tuning CTR estimation based on EE exploration
Developing salary management system based on C language course paper + source code and executable EXE file
A case of misuse of append
Mysql database DQL query operation
[path planning] week 1: hodgepodge
[GWCTF 2019]mypassword XSS
立體渲染
Reinforcement learning weekly (issue 50): saferl kit, gmi-drl, rp-sdrl & offline meta reinforcement learning
Redis big key problem