skip to Main Content

How to find sequence of Alphabets of non-ASCII (other languages) in a given string in PostgreSQL? For example, ASCII alphabets can be matched using ‘[A-Za-z]’.

In SQL Server, @ch BETWEEN ‘A’ and ‘Z’ matches the characters like Γ‘, ΓΌ, Γ„, etc.

2

Answers


  1. In PostgreSQL Regular expressions and character classesΒ can be used to match non-ASCII alphabets in a given string. Try running the following query to extract rows from your table where one or more characters from the non-ASCII alphabet are present in the ‘your_column’. For your particular case, change the table and column names as necessary.

    SELECT *
    FROM your_table
    WHERE your_column ~ 'p{L}';
    

    Hope it’s helpful πŸ™‚

    Login or Signup to reply.
  2. That depends on the collation you are using. With most natural language collations, the comparison would work:

    SELECT 'Γ±' COLLATE "en-US-x-icu" BETWEEN 'A' AND 'Z';
    
     ?column? 
    ══════════
     t
    (1 row)
    

    The easiest way to check if a string contains only alphabetic characters is a regular expression:

    SELECT NOT 'δΈ­ζ–‡Β΅xY' COLLATE "de_AT.utf8" ~ '[^[:alpha:]]';
    
     ?column? 
    ══════════
     t
    (1 row)
    
    SELECT NOT 'a+b' COLLATE "de_AT.utf8" ~ '[^[:alpha:]]';
    
     ?column? 
    ══════════
     f
    (1 row)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search