PostgreSQL 은 문자열 에 포 함 된 몇 가지 방법 을 판단 합 니 다.

6555 단어 PostgreSQLpgsqlsql
1. position(substring in string):
postgres=# select position('aa' in 'abcd');
 position 
----------
        0
(1 row)

postgres=# select position('ab' in 'abcd');
 position 
----------
        1
(1 row)

postgres=# select position('ab' in 'abcdab');
 position 
----------
        1
(1 row)1234567891011121314151617

이 를 통 해 알 수 있 듯 이 대상 문자열 이 포함 되 어 있 으 면 대상 문자열 이 나타 난 위 치 를 되 돌려 주 고 반환 값 이 0 이상 인지 에 따라 대상 문자열 이 포함 되 어 있 는 지 여 부 를 판단 할 수 있 습 니 다.
2. strpos (string, substring): 이 함수 의 역할 은 하위 문자열 의 위 치 를 설명 하 는 것 입 니 다.
postgres=# select strpos('abcd','aa');
 strpos 
--------
      0
(1 row)

postgres=# select strpos('abcd','ab');
 strpos 
--------
      1
(1 row)

postgres=# select strpos('abcdab','ab');
 strpos 
--------
      1
(1 row)1234567891011121314151617

역할 은 position 함수 와 일치 합 니 다.
3. 정규 표현 식 사용:
postgres=# select 'abcd' ~ 'aa';
 ?column? 
----------
 f
(1 row)

postgres=# select 'abcd' ~ 'ab';
 ?column? 
----------
 t
(1 row)

postgres=# select 'abcdab' ~ 'ab';
 ?column? 
----------
 t
(1 row)1234567891011121314151617

4. 배열 의 @ > 연산 자 를 사용 합 니 다 (포함 여 부 를 정확하게 판단 할 수 없습니다):
postgres=# select regexp_split_to_array('abcd','') @> array['b','e'];
 ?column? 
----------
 f
(1 row)

postgres=# select regexp_split_to_array('abcd','') @> array['a','b'];
 ?column? 
----------
 t
(1 row)1234567891011

아래 의 예 들 을 주의 하 세 요.
postgres=# select regexp_split_to_array('abcd','') @> array['a','a'];
 ?column? 
----------
 t
(1 row)

postgres=# select regexp_split_to_array('abcd','') @> array['a','c'];
 ?column? 
----------
 t
(1 row)

postgres=# select regexp_split_to_array('abcd','') @> array['a','c','a','c'];
 ?column? 
----------
 t
(1 row)1234567891011121314151617

이 를 통 해 알 수 있 듯 이 배열 의 포함 연산 자 는 판단 할 때 순서, 중복 에 관 계 없 이 포함 되 어 있 으 면 true 로 돌아 가 실제 사용 할 때 주의 하 는 것 을 알 수 있다.
다음으로 이동:https://blog.csdn.net/luojinbai/article/details/45461837

좋은 웹페이지 즐겨찾기