Reputation: 65
i have a table of users:-
|usersname|
| 52125 |
| John |
| kathy |
| 52451 |
I need to delete entries where username is made of only numbers like 52125 and 52451. i don't want to delete john and kathy. datatype of column is varchar and I'm using PostgreSQL. can someone help.
Upvotes: 0
Views: 138
Reputation: 1269753
If you want to actually remove the users from the table, use delete
:
delete from t
where username ~ '^[0-9]+$';
You can use this logic in a select
to check the rows before deleting them.
Upvotes: 1
Reputation: 127086
Something like this?
SELECT username
FROM users
WHERE username !~* '([a-z])';
Upvotes: 1
Reputation: 272106
You can use regexp to find such rows:
SELECT *
FROM t
WHERE usersname ~ '^[0-9]+$' -- user name made only of numbers
Upvotes: 3