当前位置:网站首页>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 
边栏推荐
- Es total number of data queried by criteria
- Lua -- iterator, module, meta table
- 5分钟快速上线Web应用和API(Vercel)
- A SQL optimization case using order by and rownum
- Atcoder abc256 full problem solution (interval merging template, matrix fast power optimization DP, line segment tree...)
- 【ROS 入门学习 】CmakeList.txt 和Packages.xml释义
- Solution to cache inconsistency
- Why do you perform performance tests before the software goes online? How to find a software performance testing organization
- MySQL functions
- Shell (34): time
猜你喜欢

There are 15 necessary knowledge points for the second level cost engineer before the exam! I wish you success!

欧洲的龙之城|国家地理全球最浪漫最安全的目的地

Uniapp applet mall develops thinkphp6 points mall, group purchase and seckill packaged app

Note: by the end of 2022, the printing entrance of Guangdong second-class cost engineer's admission card has been opened

考生必读篇 | PMP6月25日考试临近,需要注意什么?

Summary of just meal with 900W increase in playback and acclaim from station B users

5分钟快速上线Web应用和API(Vercel)
![下一个排列[发挥主观能动性发现规律]](/img/bb/262e1a21e4babb8d221d737ced3bcc.png)
下一个排列[发挥主观能动性发现规律]

腾讯云上传文件出现的问题:in a frame because it set ‘X-Frame-Options‘ to ‘deny‘.

自助图书馆系统-Tkinter界面和openpyxl表格综合设计案例
随机推荐
Greedy distribution problem (2)
sitl_ gazebo/include/gazebo_ opticalflow_ plugin. h:43:18: error: ‘TRUE’ was not declared in this scope
SPA项目开发之CRUD+表单验证
Several methods of changing 91 Oracle common table into partitioned table
≥ server2012r2 system, disable some planned tasks of the system
[Li mu] how to read papers [intensive reading of papers]
Valid parentheses
In the third week of June, the main growth ranking list (BiliBili platform) of station B single feigua data up was released!
Uninstall mavros
Lua-- use of data types, variables, loops, functions and operators
Las point cloud create mesh
. Net 5.0 realizes the source code analysis of the oidc authentication part of single sign on through identityserver4
Several ways of redis persistence -- deeply parsing RDB
Some shaders in AB package do not trigger the callback of ipreprocessshaders
Crud+ form verification for spa project development
There are 15 necessary knowledge points for the second level cost engineer before the exam! I wish you success!
Es total number of data queried by criteria
Pycharm configuring remote connection server development environment
LinkedList source code analysis
CyCa children's physique etiquette Shenzhen training results assessment successfully concluded