SUBSETEQ Operator

Description

The SUBSETEQ operator returns TRUE(1) when a first operand is a subset of a second operand; that is, the second one is identical to or larger than the first one. Note that SUBSETEQ is not supported if an operand is LIST type.

Syntax

collection_operand SUBSETEQ collection_operand

Example 

--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}

 

--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.

 

--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'}  {}