regex in sql

Published by onesixx on

 

filename이라는 컬럼에서 날짜형식이 일치(포함)하는 행의 날짜별 row수 구하기

SELECT REGEXP_MATCHES(filename, '[0-9]{4}-[0-9]{2}-[0-9]{2}'), count(*)
FROM TEST_Table
GROUP BY 1

filename이라는 컬럼에서 날짜만 뽑아서 비교

select * 
from TEST_Table
where SUBSTRING(filename, '\d{4}-\d{2}-\d{2}') = '2017-08-19'
 
 
http://www.postgresqltutorial.com/postgresql-regexp_matches/

regexp_matches

 

http://www.postgresqltutorial.com/postgresql-substring/

substring

--start_position , length
SELECT SUBSTRING ('PostgreSQL', 3, 3);         -- stg
SELECT SUBSTRING ('PostgreSQL' FROM 3 FOR 3); 

--regex 
SELECT SUBSTRING ('PostgreSQL', 's.g');         -- stg
SELECT SUBSTRING ('PostgreSQL' FROM 's.g'); 

 

 

Categories: Postgresql

onesixx

Blog Owner

Leave a Reply

Your email address will not be published.