Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Query Where Field DOES NOT Contain a Digit

Tags:

sql

postgresql

I have a table with an address street, I want to make sure the address contains the street as well as house/building number (saxon 17) I want to write an SQL query to find rows where field address does not contain a numeric value. How can I do this?

like image 615
liv a Avatar asked Oct 19 '14 13:10

liv a


People also ask

How do I find non numeric values in a column in SQL?

This is the way: SELECT * FROM TABLE_NAME WHERE NOT REGEXP_LIKE(COLUMN_NAME, '^-?[0-9.]+$ '); This also excludes values which contain decimals.

How do I find non numeric values in SQL Server?

SQL Server has an ISNUMERIC() function that returns 1 for numeric values and 0 for non-numeric values.

How do you check if a string contains a number in SQL?

Method 1 - Using CHARINDEX() function This function is used to search for a specific word or a substring in an overall string and returns its starting position of match. In case no word is found, then it will return 0 (zero). Let us understand this with examples.

How do I check if a field is numeric in SQL?

The ISNUMERIC() function tests whether an expression is numeric. This function returns 1 if the expression is numeric, otherwise it returns 0.


1 Answers

This can be done using a regular expression:

select *
from the_table
where address_column !~ '[0-9]'

More details about regular expressions and pattern matching can be found in the manual:
http://www.postgresql.org/docs/current/static/functions-matching.html

like image 115
a_horse_with_no_name Avatar answered Oct 08 '22 07:10

a_horse_with_no_name