11

How to select integer values only from a varchar column in PostgreSQL?

If the column contains:

abc
70
3g
71
1.5

I'd like to select only:

70
71

I'm struggling to find functions like: is_numeric, is_integer, to do something like this:

SELECT column
FROM table
WHERE isinteger(column)

Any ideas? Thank you.

1 Answer 1

13
SELECT column
FROM table
WHERE column ~ '^\d+$'
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. That seems to work fine. Mind to share a link where I can find more info about the use of the ~ symbol?
@Tom Here is the link
How do we include negative integers in the result as well?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.