Reputation: 715
I have a Postgres query that returns a column that contains multiple language words. I want to get only the results those contains A-Z and 0-9 only. How can I get the result?
Select name from table;
Upvotes: 0
Views: 1717
Reputation: 10054
This should do:
SELECT name FROM table WHERE name ~* '\A[A-Z0-9]*\Z';
If you only want uppercase letters (not clear from your question), then use the case sensitive regular expression operator:
SELECT name FROM table WHERE name ~ '\A[A-Z0-9]*\Z';
If you want at least one character, i.e. you don't want empty strings, change the *
to +
.
Upvotes: 1