Home > database >  Postgres only select rows with latin characters
Postgres only select rows with latin characters

Time:03-24

I want to use a condition in a where clause that specifies to only select rows with latin characters (and numbers). Currently I am trying this, but this also returns me rows with Cyrillic characters:

SELECT * FROM temp WHERE temp.name SIMILAR TO '%[^[:ascii:]]%';

How to only select rows that only contain latin characters (and numbers)?

CodePudding user response:

Try the following regular expression:

... WHERE name ~ '^[[:ascii:]]*$' COLLATE "C"

That means that the pattern must consist entirely of ASCII characters. Note that control characters like “newline”, spaces and other ASCII symbols like $ also are ASCII characters. If you want only letters and numbers, try

... WHERE name ~ '^[a-zA-Z0-9]*$' COLLATE "C"
  • Related