DEA-C01 · Question #105
A company has a data warehouse that contains a table that is named Sales. The company stores the table in Amazon Redshift. The table includes a column that is named city_name. The company wants to…
The correct answer is B. Select * from Sales where city_name ~ '^(San|El)*'. In Amazon Redshift (PostgreSQL-compatible), the ~ operator performs case-sensitive POSIX regex matching. The ^ character anchors the match to the start of the string, and | is the alternation (OR) operator. So ~ '^(San|El)*' matches rows where city_name begins with 'San' or…
Question
A company has a data warehouse that contains a table that is named Sales. The company stores the table in Amazon Redshift. The table includes a column that is named city_name. The company wants to query the table to find all rows that have a city_name that starts with "San" or "El". Which SQL query will meet this requirement?
Options
- ASelect * from Sales where city_name ~ '$(San|El)*';
- BSelect * from Sales where city_name ~ '^(San|El)*';
- CSelect * from Sales where city_name ~'$(San&El)*';
- DSelect * from Sales where city_name ~ '^(San&El)*';
How the community answered
(46 responses)- A4% (2)
- B76% (35)
- C7% (3)
- D13% (6)
Explanation
In Amazon Redshift (PostgreSQL-compatible), the ~ operator performs case-sensitive POSIX regex matching. The ^ character anchors the match to the start of the string, and | is the alternation (OR) operator. So ~ '^(San|El)*' matches rows where city_name begins with 'San' or 'El'. Option A uses $ (end anchor) instead of ^, so it would anchor to the end, not the beginning. Options C and D use & as the alternation operator, which is not valid regex syntax for OR-| is the correct operator.
Topics
Community Discussion
No community discussion yet for this question.