

 Amazon Redshift는 패치 198부터 새 Python UDF 생성을 더 이상 지원하지 않습니다. 기존 Python UDF는 2026년 6월 30일까지 계속 작동합니다. 자세한 내용은 [블로그 게시물](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)을 참조하세요.

# SIMILAR TO
<a name="pattern-matching-conditions-similar-to"></a>

SIMILAR TO 연산자는 열 이름 같은 문자열 표현식과 SQL 표준 정규 표현식 패턴을 일치시킵니다. SQL 정규 표현식 패턴에는 [LIKE](r_patternmatching_condition_like.md) 연산자에서 지원되는 문자 2개는 물론이고 패턴 일치 문자까지 포함될 수 있습니다.

SIMILAR TO 연산자는 패턴이 문자열 구간과 일치하는 POSIX 정규 표현식과 달리 패턴이 전체 문자열과 일치하는 경우에만 true를 반환합니다.

SIMILAR TO는 대/소문자를 구분하여 패턴을 일치시킵니다.

**참고**  
SIMILAR TO를 사용하는 정규 표현식 일치는 계산에 따른 리소스 비용이 높습니다. 따라서 특히 다수의 행을 처리할 때는 최대한 LIKE를 사용하는 것이 좋습니다. 예를 들어 다음 두 쿼리는 기능면에서 동일하지만 LIKE를 사용하는 쿼리의 실행 속도가 정규 표현식을 사용하는 쿼리보다 몇 배 더 빠릅니다.  

```
select count(*) from event where eventname SIMILAR TO '%(Ring|Die)%'; 
select count(*) from event where eventname LIKE '%Ring%' OR eventname LIKE '%Die%';
```

## 구문
<a name="pattern-matching-conditions-similar-to-synopsis"></a>

```
expression [ NOT ] SIMILAR TO pattern [ ESCAPE 'escape_char' ]
```

## 인수
<a name="pattern-matching-conditions-similar-to-arguments"></a>

 * expression*   
열 이름 같이 유효한 UTF-8 문자 표현식입니다.

SIMILAR TO  
SIMILAR TO는 대/소문자를 구분하여 *expression*의 전체 문자열과 패턴을 일치시킵니다.

 *pattern*   
SQL 표준 정규 표현식 패턴을 나타내는, 유효한 UTF-8 문자 표현식입니다.

 *escape\$1char*   
패턴의 메타 문자를 이스케이프 처리하는 문자 표현식입니다. 기본값은 백슬래시 2개('\$1\$1')입니다.

*pattern*에 메타 문자가 포함되어 있지 않으면 패턴이 문자열 자체만 의미합니다.

문자 표현식 중 하나는 CHAR 또는 VARCHAR 데이터 형식이 될 수 있습니다. 데이터 형식이 서로 다른 경우에는 Amazon Redshift가 *pattern*을 *expression*의 데이터 형식으로 변환합니다.

SIMILAR TO에서 지원되는 패턴 일치 메타 문자는 다음과 같습니다.

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/redshift/latest/dg/pattern-matching-conditions-similar-to.html)

## 예제
<a name="pattern-matching-conditions-similar-to-examples"></a>

다음 표는 SIMILAR TO를 사용한 패턴 일치의 예를 나타낸 것입니다.

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/ko_kr/redshift/latest/dg/pattern-matching-conditions-similar-to.html)

다음은 이름에 "E" 또는 "H"가 포함되는 도시를 찾는 예입니다.

```
SELECT DISTINCT city FROM users
WHERE city SIMILAR TO '%E%|%H%' ORDER BY city LIMIT 5;

      city
-----------------
 Agoura Hills
 Auburn Hills
 Benton Harbor
 Beverly Hills
 Chicago Heights
```

다음은 기본 이스케이프 문자열('`\\`')을 사용하여 "`_`"이 포함된 문자열을 찾는 예입니다.

```
SELECT tablename, "column" FROM pg_table_def
WHERE "column" SIMILAR TO '%start\\_%'
ORDER BY tablename, "column" LIMIT 5;

        tablename         |       column
--------------------------+---------------------
 stcs_abort_idle          | idle_start_time
 stcs_abort_idle          | txn_start_time
 stcs_analyze_compression | start_time
 stcs_auto_worker_levels  | start_level
 stcs_auto_worker_levels  | start_wlm_occupancy
```

다음은 '`^`'을 이스케이프 문자열로 지정한 후 이 이스케이프 문자열을 사용하여 "`_`"이 포함된 문자열을 찾는 예입니다.

```
SELECT tablename, "column" FROM pg_table_def
WHERE "column" SIMILAR TO '%start^_%' ESCAPE '^'
ORDER BY tablename, "column" LIMIT 5;

        tablename         |       column
--------------------------+---------------------
 stcs_abort_idle          | idle_start_time
 stcs_abort_idle          | txn_start_time
 stcs_analyze_compression | start_time
 stcs_auto_worker_levels  | start_level
 stcs_auto_worker_levels  | start_wlm_occupancy
```