Kohjah Breese
Kohjah Breese

Reputation: 4136

MySQL collation for Portugese

Is there a way in MySQL to have character collated as per the Portugese language? In the same way there is utf8_spanish_ci or Spanish. Or is there a way to add new collations?

There are the following characters:

ç (Gonçalves)
ã (Guimarães)
õ (Simões)
â (Tânger)
ô (Pôrto)
ê (Gouvêa)
é (Féria)
í (Vinícius)
ó (Grijó)
ú (Araújo)
á (Tomás)
ñ (Núñez)

When using utf8_general_ci searching for 'Gonçalves' would also return 'Goncalves'. I need these to be treated separately by MySQL.

Upvotes: 3

Views: 1351

Answers (3)

Peter Gulutzan
Peter Gulutzan

Reputation: 485

The above are answers for the user's question but I hope it's appropriate to warn: with a typical Portuguese collation those characters would not all be separate for searching. Wikipedia explains in https://en.wikipedia.org/wiki/Portuguese_orthography "Accented letters and digraphs are not counted as separate characters for collation purposes." and Unicode's common language data repository explains in https://github.com/unicode-org/cldr/blob/main/common/collation/pt.xml "The root collation order is valid for this language." So MySQL's default Unicode-collation-algorithm collations would usually be desirable.

Upvotes: 0

FilT
FilT

Reputation: 330

According to http://mysql.rjweb.org/utf8mb4_collations.html, and tested in MySQL, the latin1_general_ci is the collation that correctly differentiates between the characters the OP has identified

It also sorts it properly, and does not transform Ç into C for instance.

Upvotes: 0

User123456
User123456

Reputation: 2738

Please check for the collation and character set. This is an example create statement for accepting Portugese characters.

CREATE DATABASE dansih_db CHARACTER SET latin1 COLLATE latin1_danish_ci;

try altering Character Sets and Collation in you DB Example output for above character set and collation

[Check this output[1

Upvotes: 1

Related Questions