Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

purpose of collate in Postgres

Tags:

sql

postgresql

I am new to Postgres. I have just started learning it from here. I found COLLATE "C" from a select statement

SELECT not_equal(first_name, last_name COLLATE "C")

What does COLLATE "C" do?

like image 825
Harnish Avatar asked Jun 23 '16 06:06

Harnish


People also ask

What is collate in Pgadmin?

A collation is an SQL schema object that maps a SQL name to operating system locales. To create a collation, you must have a CREATE privilege on the destination schema. The Collation dialog organizes the development of a collation through the following dialog tabs: General and Definition.

What is database collation?

In database systems, Collation specifies how data is sorted and compared in a database. Collation provides the sorting rules, case, and accent sensitivity properties for the data in the database.

How do I change collate and Ctype in PostgreSQL?

You cannot to change these values for already created databases. In this moment, when there are not other databases, the most easy solution is a) stop database, b) delete data directory, c) run manually initdb with options --encoding and --locale (run this command under postgres user).

How do I make a case insensitive in PostgreSQL?

The older PostgreSQL method for performing case-insensitive text operations is the citext type; it is similar to the text type, but operators are functions between citext values are implicitly case-insensitive. The PostgreSQL docs provide more information on this type.


1 Answers

Collation is used to sort strings (text), for example by alphabetic order, whether or not case matters, how to deal with letters that have accents etc. COLLATE "C" tells the database not to use collation at all. One might use this if they were designing a database to hold data in different languages. Technically, COLLATE "C" will use byte order to drive text comparisons.

The first answer on https://dba.stackexchange.com/questions/94887/what-is-the-impact-of-lc-ctype-on-a-postgresql-database provides a good example of the differences between using COLLATE "C" vs. COLLATE "fr_FR" which uses the French localization.

like image 112
Shayna Avatar answered Oct 19 '22 16:10

Shayna