Introduction
Use SIMILAR TO to check if text matches a simple pattern using special symbols. It helps find text that looks like what you want without full complex rules.
expression SIMILAR TO pattern
'apple' SIMILAR TO 'a%'
'123abc' SIMILAR TO '[0-9]+[a-z]+'
'dog' SIMILAR TO '(cat|dog)'
SELECT 'apple' SIMILAR TO 'a%'; SELECT '123abc' SIMILAR TO '[0-9]+[a-z]+'; SELECT 'dog' SIMILAR TO '(cat|dog)'; SELECT 'bat' SIMILAR TO '(cat|dog)';
SIMILAR TO operator in PostgreSQL?name matches a pattern starting with 'A' followed by any characters using SIMILAR TO?users(name TEXT) with rows: 'Anna', 'Anny', 'Andy', 'Any', which query returns only names starting with 'An' and ending with 'y' using SIMILAR TO?SELECT * FROM products WHERE code SIMILAR TO '[A-Z]+[0-9]'. It returns no rows even though some codes look like 'AB12'. What is the likely problem?users that start with either 'admin' or 'user' followed by exactly 3 digits. Which SIMILAR TO pattern correctly matches this?Pass the test and this pattern moves unknown