当前位置:网站首页>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 
边栏推荐
- ≥ server2012r2 system, disable some planned tasks of the system
- SPA项目开发之首页导航+左侧菜单
- R language data Table data import practice: data Rename the name of the table data column (rename)
- Basic MySQL database operations
- Dynamic tree + data table + pagination of spa project development
- SPA项目开发之CRUD+表单验证
- Lua-- use of data types, variables, loops, functions and operators
- Experiment 4 operation comparison between NoSQL and relational database
- Note: by the end of 2022, the printing entrance of Guangdong second-class cost engineer's admission card has been opened
- Some shaders in AB package do not trigger the callback of ipreprocessshaders
猜你喜欢

Rapideye, spot satellite remote sensing image data

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

British teddy bear joins the pubg mobile game
![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]

What are the methods of software stress testing and how to select a software stress testing organization?
![[geometric vision] 4.2 piecewise linear transformation](/img/1e/a810f4d7e9a6a34647b5cb56fdde67.png)
[geometric vision] 4.2 piecewise linear transformation

Experiment 4 operation comparison between NoSQL and relational database

【论文解读】关于基于视觉无人机自主降落平台的论文梳理

The relationship between derivative and differential of function

新捷途X70S上市8.79万起,空间安全越级,不愧是网红国民大7座SUV
随机推荐
AtCoder abc256全题解(区间合并模板、矩阵快速幂优化dp、线段树……)
Install MySQL for Linux (package succeeded!!)
A SQL optimization case using order by and rownum
Several methods of changing 91 Oracle common table into partitioned table
SQL performance optimization method for interval retrieval
Is it bad for NFT that the market starts to cool down?
5 minutes to quickly launch web applications and APIs (vercel)
MySQL multi table operation
A case of 94 SQL optimization (the writing method used is often rejected)
Dragon City in Europe | National Geographic the most romantic and safe destination in the world
[interpretation of the paper] sort out the papers on the vision based autonomous landing platform of UAV
Eureka service registration and discovery
How to use the data dictionary function in the low code platform of the Internet of things?
立體渲染
Self service library system Tkinter interface and openpyxl form comprehensive design case
Greedy distribution problem (2)
Generate detailed API and parameters of QR code using qrcodejs2
Crud+ form verification for spa project development
自助图书馆系统-Tkinter界面和openpyxl表格综合设计案例
MySQL constraints