:meta-keywords: cubrid seteq, cubrid setneq, cubrid superset, cubrid superseteq, cubrid subset, cubrid subseteq :meta-description: Containment operators are used to check the containment relationship by performing comparison operation on operands of the collection data type. :tocdepth: 3 *********** í¬í•¨ ì—°ì‚°ìž *********** .. contents:: ì»¬ë ‰ì…˜ íƒ€ìž…ì¸ í”¼ì—°ì‚°ìž ê°„ ë¹„êµ ì—°ì‚°ì„ ìˆ˜í–‰í•˜ì—¬ í¬í•¨(containment) 관계를 확ì¸í•˜ê¸° 위해 í¬í•¨ ì—°ì‚°ìžê°€ 사용ëœë‹¤. 피연산ìžë¡œ ì»¬ë ‰ì…˜ 타입 ë˜ëŠ” 부질ì˜(subquery)를 ì§€ì •í• ìˆ˜ 있으며, ë‘ í”¼ì—°ì‚°ìžì˜ í¬í•¨ 관계(ë™ì¼í•˜ë‹¤/다르다/부분집합ì´ë‹¤/진부분집합ì´ë‹¤)ì— ë”°ë¼ **TRUE** ë˜ëŠ” **FALSE** 를 반환한다. :: <collection_operand> <containment_operator> <collection_operand> <collection_operand> ::= <set> | <multiset> | <sequence> (ë˜ëŠ” <list>) | <subquery> | NULL <containment_operator> ::= SETEQ | SETNEQ | SUPERSET | SUBSET | SUPERSETEQ | SUBSETEQ * <*collection_operand*>: 피연산ìžë¡œ ì§€ì •ë 수 있는 수ì‹ì€ í•˜ë‚˜ì˜ ì§‘í•© ê°’ ì†ì„±(SET-valued attribute)ì´ê±°ë‚˜, ì§‘í•© ì—°ì‚°ìž(SET operator)를 지닌 ì‚°ìˆ ìˆ˜ì‹(arithmetic expression)ì´ê±°ë‚˜, 중괄호로 ë‘˜ëŸ¬ì‹¸ì¸ ì§‘í•© ê°’ì´ë‹¤. ì´ë•Œ, 중괄호로 ë‘˜ëŸ¬ì‹¸ì¸ ì§‘í•© ê°’ì€ íƒ€ìž…ì„ ëª…ì‹œí•˜ì§€ ì•Šì„ ê²½ìš° 기본ì 으로 **LIST** 타입으로 처리한다. 피연산ìžë¡œ 부질ì˜ê°€ ì§€ì •ë 수 있으며, ì»¬ë ‰ì…˜ íƒ€ìž…ì´ ì•„ë‹Œ ì¹¼ëŸ¼ì„ ì¡°íšŒí•˜ëŠ” 경우ì—는 **SET** (*subquery*)ê³¼ ê°™ì´ í•´ë‹¹ 부질ì˜ì— ì»¬ë ‰ì…˜ 타입 키워드를 붙여야 한다. 부질ì˜ì—서 조회하는 ì¹¼ëŸ¼ì€ í•˜ë‚˜ì˜ ì§‘í•©ë§Œ 결과로 반환해야 나머지 í”¼ì—°ì‚°ìž ì§‘í•©ê³¼ 비êµí• 수 있다. ì»¬ë ‰ì…˜ ì›ì†Œì˜ íƒ€ìž…ì´ ì˜¤ë¸Œì 트ì´ë©´, 오브ì íŠ¸ì˜ ë‚´ìš©ì´ ì•„ë‹Œ ê°ì²´ ì‹ë³„ìž(OID, object identifier)ì— ëŒ€í•´ 비êµí•œë‹¤. 예를 들어, ê°™ì€ ì†ì„± ê°’ì„ ê°–ê³ OIDê°€ 다른 ë‘ ì˜¤ë¸Œì 트는 서로 다른 것으로 간주한다. * **NULL**: ë¹„êµ ëŒ€ìƒì´ ë˜ëŠ” í”¼ì—°ì‚°ìž ì¤‘ ì–´ëŠ í•˜ë‚˜ê°€ **NULL** ì¸ ê²½ìš°, **NULL** ì´ ë°˜í™˜ëœë‹¤. 다ìŒì€ CUBRIDê°€ ì§€ì›í•˜ëŠ” í¬í•¨ ì—°ì‚°ìžì— 관한 설명 ë° ë¦¬í„´ ê°’ì„ ë‚˜íƒ€ë‚¸ 표ì´ë‹¤. **CUBRIDê°€ ì§€ì›í•˜ëŠ” í¬í•¨ ì—°ì‚°ìž** +----------------+-------------------------------------+--------------------------+----------+ | í¬í•¨ ì—°ì‚°ìž | 설명 | ì¡°ê±´ì‹ | 리턴 ê°’ | +================+=====================================+==========================+==========+ | A | A = B: | {1,2} SETEQ {1,2,2} | 0 | | **SETEQ** | ì§‘í•© A와 ì§‘í•© Bì˜ ì›ì†Œê°€ 서로 같다. | | | | B | | | | +----------------+-------------------------------------+--------------------------+----------+ | A | A <> B: | {1,2} SETNEQ {1,2,3} | 1 | | **SETNEQ** | ì§‘í•© A와 ì§‘í•© Bì˜ ì›ì†Œê°€ 같지 않다. | | | | B | | | | +----------------+-------------------------------------+--------------------------+----------+ | A | A > B: | {1,2} SUPERSET {1,2,3} | 0 | | **SUPERSET** | ì§‘í•© B는 ì§‘í•© Aì˜ ì§„ 부분집합ì´ë‹¤. | | | | B | | | | +----------------+-------------------------------------+--------------------------+----------+ | A | A < B: | {1,2} SUBSET {1,2,3} | 1 | | **SUBSET** | ì§‘í•© A는 ì§‘í•© Bì˜ ì§„ 부분집합ì´ë‹¤. | | | | B | | | | +----------------+-------------------------------------+--------------------------+----------+ | A | A >= B: | {1,2} SUPERSETEQ {1,2,3} | 0 | | **SUPERSETEQ** | ì§‘í•© B는 ì§‘í•© Aì˜ ë¶€ë¶„ ì§‘í•©ì´ë‹¤. | | | | B | | | | +----------------+-------------------------------------+--------------------------+----------+ | A | A <= B: | {1,2} SUBSETEQ {1,2,3} | 1 | | **SUBSETEQ** | ì§‘í•© A는 ì§‘í•© Bì˜ ë¶€ë¶„ ì§‘í•©ì´ë‹¤. | | | | B | | | | +----------------+-------------------------------------+--------------------------+----------+ 다ìŒì€ í¬í•¨ ì—°ì‚°ìžë¥¼ ì´ìš©í•˜ëŠ” 경우, 피연산ìžì˜ 타입별 ì—°ì‚° 가능 여부 ë° íƒ€ìž… 변환 여부를 나타낸 표ì´ë‹¤. **í¬í•¨ ì—°ì‚°ìžì˜ í”¼ì—°ì‚°ìž íƒ€ìž…ë³„ ì—°ì‚° 가능 여부** +---------------------+-----------+------------------+-------------------------+ | | SET | MULTISET | LIST(=SEQUENCE) | +=====================+===========+==================+=========================+ | **SET** | ì—°ì‚° 가능 | ì—°ì‚° 가능 | ì—°ì‚° 가능 | +---------------------+-----------+------------------+-------------------------+ | **MULTISET** | ì—°ì‚° 가능 | ì—°ì‚° 가능 | ì—°ì‚° 가능 | | | | | (**LIST** íƒ€ìž…ì€ | | | | | **MULTISET** | | | | | 타입으로 변환ë¨) | +---------------------+-----------+------------------+-------------------------+ | **LIST(=SEQUENCE)** | ì—°ì‚° 가능 | ì—°ì‚° 가능 | ì¼ë¶€ ì—°ì‚°ë§Œ 가능 | | | | (**LIST** íƒ€ìž…ì€ | (**SETEQ**, **SETNEQ**) | | | | **MULTISET** | 나머지 ì—°ì‚°ì€ | | | | 타입으로 변환ë¨) | ì—러 ë°œìƒ | +---------------------+-----------+------------------+-------------------------+ .. code-block:: sql --empty set is a subset of any set SELECT ({} SUBSETEQ (CAST ({3,1,2} AS SET))); :: Result ============= 1 .. code-block:: sql --operation between set type and null returns null SELECT ((CAST ({3,1,2} AS SET)) SUBSETEQ NULL); :: Result ============= NULL .. code-block:: sql --{1,2,3} seteq {1,2,3} returns true SELECT ((CAST ({3,1,2} AS SET)) SETEQ (CAST ({1,2,3,3} AS SET))); :: Result ============= 1 .. code-block:: sql --{1,2,3} seteq {1,2,3,3} returns false SELECT ((CAST ({3,1,2} AS SET)) SETEQ (CAST ({1,2,3,3} AS MULTISET))); :: Result ============= 0 .. code-block:: sql --{1,2,3} setneq {1,2,3,3} returns true SELECT ((CAST ({3,1,2} AS SET)) SETNEQ (CAST ({1,2,3,3} AS MULTISET))); :: Result ============= 1 .. code-block:: sql --{1,2,3} subseteq {1,2,3,4} returns true SELECT ((CAST ({3,1,2} AS SET)) SUBSETEQ (CAST ({1,2,4,4,3} AS SET))); :: Result ============= 1 .. code-block:: sql --{1,2,3} subseteq {1,2,3,4,4} returns true SELECT ((CAST ({3,1,2} AS SET)) SUBSETEQ (CAST ({1,2,4,4,3} AS MULTISET))); :: Result ============= 1 .. code-block:: sql --{1,2,3} subseteq {1,2,4,4,3} returns true SELECT ((CAST ({3,1,2} AS SET)) SUBSETEQ (CAST ({1,2,4,4,3} AS LIST))); :: Result ============= 0 .. code-block:: sql --{1,2,3} subseteq {1,2,3,4,4} returns true SELECT ((CAST ({3,1,2} AS SET)) SUBSETEQ (CAST ({1,2,3,4,4} AS LIST))); :: Result ============= 1 .. code-block:: sql --{3,1,2} seteq {3,1,2} returns true SELECT ((CAST ({3,1,2} AS LIST)) SETEQ (CAST ({3,1,2} AS LIST))); :: Result ============= 1 .. code-block:: sql --error occurs because LIST subseteq LIST is not supported SELECT ((CAST ({3,1,2} AS LIST)) SUBSETEQ (CAST ({3,1,2} AS LIST))); :: ERROR: ' subseteq ' operator is not defined on types sequence and sequence. SETEQ ===== **SETEQ** ì—°ì‚°ìžëŠ” 첫 번째 피연산ìžì™€ ë‘ ë²ˆì§¸ 피연산ìžê°€ ë™ì¼í•œ 경우 **TRUE** (1)ì„ ë°˜í™˜í•œë‹¤. ëª¨ë“ ì»¬ë ‰ì…˜ íƒ€ìž…ì— ëŒ€í•´ ë¹„êµ ì—°ì‚°ì„ ìˆ˜í–‰í• ìˆ˜ 있다. :: collection_operand SETEQ collection_operand .. code-block:: sql --creating a table with SET type address column and LIST type zip_code column CREATE TABLE contain_tbl (id INT PRIMARY KEY, name CHAR(10), address SET VARCHAR(20), zip_code LIST INT); INSERT INTO contain_tbl VALUES(1, 'Kim', {'country', 'state'},{1, 2, 3}); INSERT INTO contain_tbl VALUES(2, 'Moy', {'country', 'state'},{3, 2, 1}); INSERT INTO contain_tbl VALUES(3, 'Jones', {'country', 'state', 'city'},{1,2,3,4}); INSERT INTO contain_tbl VALUES(4, 'Smith', {'country', 'state', 'city', 'street'},{1,2,3,4}); INSERT INTO contain_tbl VALUES(5, 'Kim', {'country', 'state', 'city', 'street'},{1,2,3,4}); INSERT INTO contain_tbl VALUES(6, 'Smith', {'country', 'state', 'city', 'street'},{1,2,3,5}); INSERT INTO contain_tbl VALUES(7, 'Brown', {'country', 'state', 'city', 'street'},{}); --selecting rows when two collection_operands are same in the WEHRE clause SELECT id, name, address, zip_code FROM contain_tbl WHERE address SETEQ {'country','state', 'city'}; :: id name address zip_code =============================================================================== 3 'Jones ' {'city', 'country', 'state'} {1, 2, 3, 4} 1 row selected. .. code-block:: sql --selecting rows when two collection_operands are same in the WEHRE clause SELECT id, name, address, zip_code FROM contain_tbl WHERE zip_code SETEQ {1,2,3}; :: id name address zip_code =============================================================================== 1 'Kim ' {'country', 'state'} {1, 2, 3} 1 rows selected. SETNEQ ====== **SETNEQ** ì—°ì‚°ìžëŠ” 첫 번째 피연산ìžì™€ ë‘ ë²ˆì§¸ 피연산ìžê°€ ë™ì¼í•˜ì§€ ì•Šì€ ê²½ìš°ì— **TRUE** (1)ì„ ë°˜í™˜í•œë‹¤. ëª¨ë“ ì»¬ë ‰ì…˜ íƒ€ìž…ì— ëŒ€í•´ ë¹„êµ ì—°ì‚°ì„ ìˆ˜í–‰í• ìˆ˜ 있다. :: collection_operand SETNEQ collection_operand .. code-block:: sql --selecting rows when two collection_operands are not same in the WEHRE clause SELECT id, name, address, zip_code FROM contain_tbl WHERE address SETNEQ {'country','state', 'city'}; :: id name address zip_code =============================================================================== 1 'Kim ' {'country', 'state'} {1, 2, 3} 2 'Moy ' {'country', 'state'} {3, 2, 1} 4 'Smith ' {'city', 'country', 'state', 'street'} {1, 2, 3, 4} 5 'Kim ' {'city', 'country', 'state', 'street'} {1, 2, 3, 4} 6 'Smith ' {'city', 'country', 'state', 'street'} {1, 2, 3, 5} 7 'Brown ' {'city', 'country', 'state', 'street'} {} 6 rows selected. .. code-block:: sql --selecting rows when two collection_operands are not same in the WEHRE clause SELECT id, name, address, zip_code FROM contain_tbl WHERE zip_code SETNEQ {1,2,3}; :: id name address zip_code =============================================================================== 2 'Moy ' {'country', 'state'} {3, 2, 1} 3 'Jones ' {'city', 'country', 'state'} {1, 2, 3, 4} 4 'Smith ' {'city', 'country', 'state', 'street'} {1, 2, 3, 4} 5 'Kim ' {'city', 'country', 'state', 'street'} {1, 2, 3, 4} 6 'Smith ' {'city', 'country', 'state', 'street'} {1, 2, 3, 5} 7 'Brown ' {'city', 'country', 'state', 'street'} {} SUPERSET ======== **SUPERSET** ì—°ì‚°ìžëŠ” 첫 번째 피연산ìžê°€ ë‘ ë²ˆì§¸ 피연산ìžì˜ ëª¨ë“ ì›ì†Œë¥¼ í¬í•¨í•˜ëŠ” 경우, 즉 ë‘ ë²ˆì§¸ 피연산ìžê°€ 첫 번째 피연산ìžì˜ ì§„ë¶€ë¶„ì§‘í•©ì¸ ê²½ìš° **TRUE** (1)ì„ ë°˜í™˜í•œë‹¤. í”¼ì—°ì‚°ìž ì§‘í•©ì´ ì„œë¡œ ë™ì¼í•œ 경우ì—는 **FALSE** (0)ì„ ë°˜í™˜í•œë‹¤. 단, 피연산ìžê°€ ëª¨ë‘ **LIST** íƒ€ìž…ì¸ ê²½ìš°ì—는 **SUPERSET** ì—°ì‚°ì„ ì§€ì›í•˜ì§€ 않는다. :: collection_operand SUPERSET collection_operand .. code-block:: sql --selecting rows when the first operand is a superset of the second operand and they are not same SELECT id, name, address, zip_code FROM contain_tbl WHERE address SUPERSET {'country','state','city'}; :: id name address zip_code =============================================================================== 4 'Smith ' {'city', 'country', 'state', 'street'} {1, 2, 3, 4} 5 'Kim ' {'city', 'country', 'state', 'street'} {1, 2, 3, 4} 6 'Smith ' {'city', 'country', 'state', 'street'} {1, 2, 3, 5} 7 'Brown ' {'city', 'country', 'state', 'street'} {} .. code-block:: sql --SUPERSET operator cannot be used for comparison between LIST and LIST type values SELECT id, name, address, zip_code FROM contain_tbl WHERE zip_code SUPERSET {1,2,3}; :: ERROR: ' superset ' operator is not defined on types sequence and sequence. .. code-block:: sql --Comparing operands with a SUPERSET operator after casting LIST type as SET type SELECT id, name, address, zip_code FROM contain_tbl WHERE zip_code SUPERSET (CAST ({1,2,3} AS SET)); :: id name address zip_code =============================================================================== 3 'Jones ' {'city', 'country', 'state'} {1, 2, 3, 4} 4 'Smith ' {'city', 'country', 'state', 'street'} {1, 2, 3, 4} 5 'Kim ' {'city', 'country', 'state', 'street'} {1, 2, 3, 4} 6 'Smith ' {'city', 'country', 'state', 'street'} {1, 2, 3, 5} SUPERSETEQ ========== **SUPERSETEQ** ì—°ì‚°ìžëŠ” 첫 번째 피연산ìžê°€ ë‘ ë²ˆì§¸ 피연산ìžì˜ ëª¨ë“ ì›ì†Œë¥¼ í¬í•¨í•˜ê±°ë‚˜ 서로 ë™ì¼í•œ 경우, 즉 ë‘ ë²ˆì§¸ 피연산ìžê°€ 첫 번째 피연산ìžì˜ ë¶€ë¶„ì§‘í•©ì¸ ê²½ìš° **TRUE** (1)를 반환한다. 단, 피연산ìžê°€ ëª¨ë‘ **LIST** íƒ€ìž…ì¸ ê²½ìš°ì—는 **SUPERSETEQ** ì—°ì‚°ì„ ì§€ì›í•˜ì§€ 않는다. :: collection_operand SUPERSETEQ collection_operand .. code-block:: sql --selecting rows when the first operand is a superset of the second operand SELECT id, name, address, zip_code FROM contain_tbl WHERE address SUPERSETEQ {'country','state','city'}; :: id name address zip_code =============================================================================== 3 'Jones ' {'city', 'country', 'state'} {1, 2, 3, 4} 4 'Smith ' {'city', 'country', 'state', 'street'} {1, 2, 3, 4} 5 'Kim ' {'city', 'country', 'state', 'street'} {1, 2, 3, 4} 6 'Smith ' {'city', 'country', 'state', 'street'} {1, 2, 3, 5} 7 'Brown ' {'city', 'country', 'state', 'street'} {} .. code-block:: sql --SUPERSETEQ operator cannot be used for comparison between LIST and LIST type values SELECT id, name, address, zip_code FROM contain_tbl WHERE zip_code SUPERSETEQ {1,2,3}; :: ERROR: ' superseteq ' operator is not defined on types sequence and sequence. .. code-block:: sql --Comparing operands with a SUPERSETEQ operator after casting LIST type as SET type SELECT id, name, address, zip_code FROM contain_tbl WHERE zip_code SUPERSETEQ (CAST ({1,2,3} AS SET)); :: id name address zip_code =============================================================================== 1 'Kim ' {'country', 'state'} {1, 2, 3} 3 'Jones ' {'city', 'country', 'state'} {1, 2, 3, 4} 4 'Smith ' {'city', 'country', 'state', 'street'} {1, 2, 3, 4} 5 'Kim ' {'city', 'country', 'state', 'street'} {1, 2, 3, 4} 6 'Smith ' {'city', 'country', 'state', 'street'} {1, 2, 3, 5} SUBSET ====== **SUBSET** ì—°ì‚°ìžëŠ” ë‘ ë²ˆì§¸ 피연산ìžê°€ 첫 번째 피연산ìžì˜ ëª¨ë“ ì›ì†Œë¥¼ í¬í•¨í•˜ëŠ” 경우, 즉 첫 번째 피연산ìžê°€ ë‘ ë²ˆì§¸ 피연산ìžì˜ ì§„ë¶€ë¶„ì§‘í•©ì¸ ê²½ìš° **TRUE** (1)ì„ ë°˜í™˜í•œë‹¤. í”¼ì—°ì‚°ìž ì§‘í•©ì´ ì„œë¡œ ë™ì¼í•œ 경우ì—는 **FALSE** (0)ì„ ë°˜í™˜í•œë‹¤. 단, 피연산ìžê°€ ëª¨ë‘ **LIST** íƒ€ìž…ì¸ ê²½ìš°ì—는 **SUBSET** ì—°ì‚°ì„ ì§€ì›í•˜ì§€ 않는다. :: collection_operand SUBSET collection_operand .. code-block:: sql --selecting rows when the first operand is a subset of the second operand and they are not same SELECT id, name, address, zip_code FROM contain_tbl WHERE address SUBSET {'country','state','city'}; :: id name address zip_code =============================================================================== 1 'Kim ' {'country', 'state'} {1, 2, 3} 2 'Moy ' {'country', 'state'} {3, 2, 1} --SUBSET operator cannot be used for comparison between LIST and LIST type values SELECT id, name, address, zip_code FROM contain_tbl WHERE zip_code SUBSET {1,2,3}; :: ERROR: ' subset ' operator is not defined on types sequence and sequence. --Comparing operands with a SUBSET operator after casting LIST type as SET type SELECT id, name, address, zip_code FROM contain_tbl WHERE zip_code SUBSET (CAST ({1,2,3} AS SET)); :: id name address zip_code =============================================================================== 7 'Brown ' {'city', 'country', 'state', 'street'} {} SUBSETEQ ======== **SUBSETEQ** ì—°ì‚°ìžëŠ” ë‘ ë²ˆì§¸ 피연산ìžê°€ 첫 번째 피연산ìžì˜ ëª¨ë“ ì›ì†Œë¥¼ í¬í•¨í•˜ê±°ë‚˜ 서로 ë™ì¼í•œ 경우, 즉 첫 번째 피연산ìžê°€ ë‘ ë²ˆì§¸ 피연산ìžì˜ ë¶€ë¶„ì§‘í•©ì¸ ê²½ìš° **TRUE** (1)ì„ ë°˜í™˜í•œë‹¤. 단, 피연산ìžê°€ ëª¨ë‘ **LIST** íƒ€ìž…ì¸ ê²½ìš°ì—는 **SUBSETEQ** ì—°ì‚°ì„ ì§€ì›í•˜ì§€ 않는다. :: collection_operand SUBSETEQ collection_operand .. code-block:: sql --selecting rows when the first operand is a subset of the second operand SELECT id, name, address, zip_code FROM contain_tbl WHERE address SUBSETEQ {'country','state','city'}; :: id name address zip_code =============================================================================== 1 'Kim ' {'country', 'state'} {1, 2, 3} 2 'Moy ' {'country', 'state'} {3, 2, 1} 3 'Jones ' {'city', 'country', 'state'} {1, 2, 3, 4} .. code-block:: sql --SUBSETEQ operator cannot be used for comparison between LIST and LIST type values SELECT id, name, address, zip_code FROM contain_tbl WHERE zip_code SUBSETEQ {1,2,3}; :: ERROR: ' subseteq ' operator is not defined on types sequence and sequence. .. code-block:: sql --Comparing operands with a SUBSETEQ operator after casting LIST type as SET type SELECT id, name, address, zip_code FROM contain_tbl WHERE zip_code SUBSETEQ (CAST ({1,2,3} AS SET)); :: id name address zip_code =============================================================================== 1 'Kim ' {'country', 'state'} {1, 2, 3} 7 'Brown ' {'city', 'country', 'state', 'street'} {}