SUBSET 연산자는 두 번째 피연산자가 첫 번째 피연산자의 모든 원소를 포함하는 경우, 즉 첫 번째 피연산자가 두 번째 피연산자의 진부분집합인 경우 TRUE(1)을 반환한다. 피연산자 집합이 서로 동일한 경우에는 FALSE(0)을 반환한다. 단, 피연산자가 모두 LIST 타입인 경우에는 SUBSET 연산을 지원하지 않는다.
collection_operand SUBSET collection_operand
--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'} {}