PostgreSQL 은 문자열 에 포 함 된 몇 가지 방법 을 판단 합 니 다.
6555 단어 PostgreSQLpgsqlsql
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
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Redmine 데이터베이스를 MySQL에서 PostgreSQL로 마이그레이션 (보충)Redmine 의 Database 를 MySQL 로 운용하고 있었습니다만, MySQL 5.6 이상이나 MariaDB 에는 , , 이러한 티켓이 수년 동안 방치된 상황을 감안하여, PostgreSQL로 마이그레이션하기...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.