regexp_matches()를 select에서 쓸 경우

해당 매치가 되지 않는 항목에 대해서는 버려진다 -ㅁ-!

즉, 1000개 중에 매칭되지 않는게 200개가 있으면

800개만 나오는데

매치 되지 않는 녀석들을 뽑아 내려면 아래와 같은 트릭을 쓰면 된다고 한다.

일단은 나의 경우에는 null 이었고, null을 내보내 주긴 하는데 값이 있는데 매칭이 안되는건 모르겠네?

with test_data as (
  select 'abc 123' as txt
  union
  select 'abc 456' as txt
  union
  select 'blah' as txt
)

select
  txt,
  (select regexp_matches(txt, '\d+'))[1] as first_num
from
  test_data

[링크 : https://dba.stackexchange.com/questions/210047/postgres-return-default-value-if-regex-match-fails]

'프로그램 사용 > postgreSQL' 카테고리의 다른 글

postgresql vacuum  (0) 2019.10.16
pgadmin4 분석기능  (0) 2019.10.16
sql 결과 공백 제거  (0) 2019.10.15
postgres 배열 처리하기  (0) 2019.10.15
sql with ,  (0) 2019.10.10
Posted by 구차니