简体   繁体   中英

Extract specific alphabetic characters using SQL query

Background: I am using PostgreSQL 11 on CentOS. I have a database having UTF-8 encoding, in specific tables I have some Latin characters as follows [ÄéÒçòý]

Objective: I want to replace those with standard English characters for that I am trying to use the following query to list down those specific characters but getting all characters set :

SELECT name_0 from public.gadm36_0_iso2_iso3 where name_0 ~ '[[:alpha:]]'; 

在此处输入图片说明

I am searching on my side and referring to some posts as well.

Any help/any suggestions would be great !!!

Perhaps you are looking for unaccent :

CREATE EXTENSION unaccent;

SELECT unaccent('ÄéÒçòý');

 unaccent 
----------
 AeOcoy
(1 row)

You can use regular expressions for this

SELECT 'ÄéÒçòý' ~* '\\A[A-Z0-9]*\\Z';

The output should be false for the above SQL statement. So use this in your where clause.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM