Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 287
Tom Avatar asked Mar 01 '13 17:03

Tom


People also ask

How to create a varchar table in PostgreSQL?

Consider a table named TEXTS to understand the examples of the PostgreSQL VARCHAR data type. Let’s create a table named TEXTS by using CREATE TABLE statement as follows, Now insert some data in the TEXTS table by using the INSERT INTO statement as follows,

How to select only non-numeric values from varchar column in MySQL?

How to select only non - numeric values from varchar column in MySQL? You need to use REGEXP for this. The syntax is as follows To understand the concept, let us create a table.

What are the examples of PostgreSQL select?

Following are the examples of postgresql select: Let us create one example and insert a few records in the table to learn how to use a select clause to retrieve the records. Open your PostgreSQL command-line prompt and enter the following command to create a table named educba –

What is the data type for characters in PostgreSQL?

Generally, for using the data type for characters, the VARCHAR is used, as it has the capability to store the values with variable length. Consider a table named TEXTS to understand the examples of the PostgreSQL VARCHAR data type.


1 Answers

SELECT column
FROM table
WHERE column ~ '^\d+$'
like image 115
Clodoaldo Neto Avatar answered Sep 16 '22 11:09

Clodoaldo Neto