Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 847707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:49:43+00:00 2026-05-15T06:49:43+00:00

Is there any way in PostgreSQL to convert UTF-8 characters to similar ASCII characters?

  • 0

Is there any way in PostgreSQL to convert UTF-8 characters to “similar” ASCII characters?

String glāžšķūņu rūķīši would have to be converted to glazskunu rukisi. UTF-8 text is not in some specific language, it might be in Latvian, Russian, English, Italian or any other language.

This is needed for using in where clause, so it might be just “comparing strings” rather than “converting strings”.

I tried using convert, but it does not give desired results (e.g., select convert('Ā', 'utf8', 'sql_ascii') gives \304\200, not A).

Database is created with:

ENCODING = 'UTF8'
LC_COLLATE = 'Latvian_Latvia.1257'
LC_CTYPE = 'Latvian_Latvia.1257'

These params may be changed, if necessary.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:49:44+00:00Added an answer on May 15, 2026 at 6:49 am

    I found different ways to do this on the PostgreSQL Wiki.

    In plperl:

    CREATE OR REPLACE FUNCTION unaccent_string(text) RETURNS text AS $$
    my ($input_string) = @_;
    $input_string =~ s/[âãäåāăą]/a;
    $input_string =~ s/[ÁÂÃÄÅĀĂĄ]/A;
    $input_string =~ s/[èééêëēĕėęě]/e;
    $input_string =~ s/[ĒĔĖĘĚ]/E;
    $input_string =~ s/[ìíîïìĩīĭ]/i;
    $input_string =~ s/[ÌÍÎÏÌĨĪĬ]/I;
    $input_string =~ s/[óôõöōŏő]/o;
    $input_string =~ s/[ÒÓÔÕÖŌŎŐ]/O;
    $input_string =~ s/[ùúûüũūŭů]/u;
    $input_string =~ s/[ÙÚÛÜŨŪŬŮ]/U;
    return $input_string;
    $$ LANGUAGE plperl;
    

    In pure SQL:

    CREATE OR REPLACE FUNCTION unaccent_string(text)
    RETURNS text
    IMMUTABLE
    STRICT
    LANGUAGE SQL
    AS $$
    SELECT translate(
        $1,
        'âãäåāăąÁÂÃÄÅĀĂĄèééêëēĕėęěĒĔĖĘĚìíîïìĩīĭÌÍÎÏÌĨĪĬóôõöōŏőÒÓÔÕÖŌŎŐùúûüũūŭůÙÚÛÜŨŪŬŮ',
        'aaaaaaaaaaaaaaaeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiooooooooooooooouuuuuuuuuuuuuuuu'
    );
    $$;
    

    And in plpython:

    create or replace function unaccent(text) returns text language plpythonu as $$
    import unicodedata
    rv = plpy.execute("select setting from pg_settings where name = 'server_encoding'");
    encoding = rv[0]["setting"]
    s = args[0].decode(encoding)
    s = unicodedata.normalize("NFKD", s)
    s = ''.join(c for c in s if ord(c) < 127)
    return s
    $$;
    

    In your case, a translate() call with all the characters you can find in the UTF-8 table should be enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to enumerate rows of query in postgresql? I have table
Is there any way how to express a variable in PostgreSQL as a string?
Is there any way to have a function in PostgreSQL return an arbitrary type?
Is there any way I can set a formatter on models that will convert
Is there any way in which I can automatically convert a Custom Class Object
Is there any way to convert a 6-digit ordinal date (days since January 1,
Is there any way, in PostgreSQL accessed from Python using SQLObject, to create a
Simple question, is there any way to omit the double quote in PostgreSQL? Here
Is there any way in PostgreSQL to look up the day of the week
Is there any way I can get django to store my data in postgresql

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.