Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find all characters in a table column of MySQL database?

Tags:

mysql

Is there any easy way to find out all characters used in a specific column of a table in MySQL?

For example, these records:

"title"
"DP&E"
"UI/O"
"B,B@M"

All the characters used in the "title" column would be: DPEUIOBM&/@,

like image 425
datasn.io Avatar asked May 19 '11 02:05

datasn.io


People also ask

How can I get column details of a table in MySQL?

You can get the MySQL table columns data type with the help of “information_schema. columns”. SELECT DATA_TYPE from INFORMATION_SCHEMA. COLUMNS where table_schema = 'yourDatabaseName' and table_name = 'yourTableName'.

How do I find a character in MySQL?

MySQL LOCATE() Function The LOCATE() function returns the position of the first occurrence of a substring in a string. If the substring is not found within the original string, this function returns 0. This function performs a case-insensitive search. Note: This function is equal to the POSITION() function.

How do I find the character set of a MySQL database?

MySQL Server supports multiple character sets, including several Unicode character sets. To display the available character sets, use the INFORMATION_SCHEMA CHARACTER_SETS table or the SHOW CHARACTER SET statement.

How do you search for a string in all fields of every table in a MySQL database?

There is a Schemas tab on the side menu bar, click on the Schemas tab, then double click on a database to select the database you want to search. Then go to menu Database - Search Data, and enter the text you are searching for, click on Start Search.


1 Answers

I'm not aware of any means to do this easily using MySQL. The best you'll be able to do is to test each potential character one by one with exists statements. This will be very slow, too, since it'll lead to reading your whole table as many times as there are characters that are not present.

If you've the possibility, create a temporary table that aggregates your needed data into a huge text field, dump it, and populate a compatible table in PostgreSQL. This will allow you to extract the needed data using a query that looks like this:

select distinct regexp_split_to_table(yourfield, '') as letter
from yourtable;

It'll still be very slow, but at least you'll go through the data a single time.

like image 115
Denis de Bernardy Avatar answered Oct 18 '22 07:10

Denis de Bernardy