The BETWEEN operator tests if a value is within a specified range.
It uses the syntax value BETWEEN min AND max:
CREATE JOB function_operator_example ADD_MISSING_COLUMNS = true ASINSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data MAP_COLUMNS_BY_NAMESELECT3BETWEEN2AND6as between_example -- evaluates to trueFROM default_glue_catalog.upsolver_samples.orders_raw_data WHERE time_filter()LIMIT1;
The statement shown above is equivalent to the following statement:
CREATE JOB function_operator_example ADD_MISSING_COLUMNS = true ASINSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data MAP_COLUMNS_BY_NAMESELECT3>=2AND3<=6as between_example -- evaluates to trueFROM default_glue_catalog.upsolver_samples.orders_raw_data WHERE time_filter()LIMIT1;
To test if a value does not fall within the specified range use NOT BETWEEN:
CREATE JOB function_operator_example ADD_MISSING_COLUMNS = true ASINSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data MAP_COLUMNS_BY_NAMESELECT3NOTBETWEEN2AND6as between_example -- evaluates to falseFROM default_glue_catalog.upsolver_samples.orders_raw_data WHERE time_filter()LIMIT1;
The statement shown above is equivalent to the following statement:
CREATE JOB function_operator_example ADD_MISSING_COLUMNS = true ASINSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data MAP_COLUMNS_BY_NAMESELECT3<2OR3>6as between_example -- evaluates to falseFROM default_glue_catalog.upsolver_samples.orders_raw_data WHERE time_filter()LIMIT1;
The presence of null in a BETWEEN or NOT BETWEEN statement will result in the statement evaluating to null:
CREATE JOB function_operator_example ADD_MISSING_COLUMNS = true ASINSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data MAP_COLUMNS_BY_NAMESELECTnull::bigintBETWEEN2AND4as between_example1, -- evaluates to null2BETWEENnull::bigintAND6as between_example2 -- evaluates to nullFROM default_glue_catalog.upsolver_samples.orders_raw_data WHERE time_filter()LIMIT1;
The BETWEEN and NOT BETWEEN operators can also be used to evaluate string arguments:
CREATE JOB function_operator_example ADD_MISSING_COLUMNS = true ASINSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data MAP_COLUMNS_BY_NAMESELECT'Paul'BETWEEN'John'AND'Ringo'as between_example, -- evaluates to trueFROM default_glue_catalog.upsolver_samples.orders_raw_data WHERE time_filter()LIMIT1;
Note that the value, min, and max parameters for BETWEEN and NOT BETWEEN must be of the same type. For example, the query produces an error if you ask if 'John' BETWEEN 2.3 AND 35.2.