Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect if a column contains special characters in postgresql table

I have a table in PostgreSQL and I need to detect if a column contains special characters like #,$,^,&,*,@,! etc. or is empty.

For example the table might be like this

enter image description here

How to write a query like this?

like image 871
Sathish Avatar asked Oct 15 '12 12:10

Sathish


People also ask

How do I find special characters in PostgreSQL?

SELECT * FROM spatial_ref_sys WHERE srtext LIKE '%\ /%'; Sometimes these ticks are very useful for searching special characters in a database.

How do I do a wildcard search in PostgreSQL?

You construct a pattern by combining literal values with wildcard characters and use the LIKE or NOT LIKE operator to find the matches. PostgreSQL provides you with two wildcards: Percent sign ( % ) matches any sequence of zero or more characters. Underscore sign ( _ ) matches any single character.

How do I ignore special characters in PostgreSQL?

Using function regexp_replace() Using regexp_replace we can remove the special characters from the string or columns.

How do I get column information in PostgreSQL?

To list down all tables columns on a specific table in the a PostgreSQL database using psql command-line, you can use \dS your_table_name.


1 Answers

Finally i got the solution

select * from table where column1 ~* '[^a-z0-9]' or column2  ~* '[^a-z0-9]' or column3  ~* '[^a-z0-9]'
like image 176
Sathish Avatar answered Sep 23 '22 01:09

Sathish