Reputation: 219
So basically i have an ic column in my db: ic only contains numbers but the field is a string so people can add passport also. i want to write a query where it only shows me ic which are only numbers:
SELECT applications.ic
FROM applications
WHERE applications LIKE '%[^0-9]%'
But it dosent work!
Upvotes: 0
Views: 1088
Reputation: 121000
PostgreSQL supports POSIX regular expressions:
SELECT applications.ic
FROM applications
WHERE applications.ic ~ '^\d+$'
The regular expression here is:
^
— matches the beginning of the string\d
— matches a digit+
— one or more modifier applied to the previous matcher$
— matches the end of the stringUpvotes: 8