Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does COLLATE pg_catalog."default" do on text attribute in postgres database table?

Tags:

postgresql

One of the fields while creating the table is described as below

id text COLLATE pg_catalog."default"
like image 505
Saurabh Bhatia Avatar asked May 16 '17 17:05

Saurabh Bhatia


People also ask

What is collation default in Postgres?

Often the default collation is set by initdb when the PostgreSQL cluster is first created. The collation and other locale components can be set using defaults from the operating system environment, and then inherited by databases created later.

What is Pg_catalog?

The PostgreSQL Catalog. PostgreSQL stores the metadata information about the database and cluster in the schema 'pg_catalog'. This information is partially used by PostgreSQL itself to keep track of things itself, but it also is presented so external people / processes can understand the inside of the databases too.

What is C collation in PostgreSQL?

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.

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).


1 Answers

It's just telling that you're using default lc_collate for this column.

But what's the default collate? Use SHOW to discover that.

SHOW lc_collate;

PostgreSQL allows to create columns with different types of collation:

CREATE TABLE collate_test
(
  default_collate text, --Default collation
  custom_collate text COLLATE pg_catalog."C" --Custom collation
);

Did you see the difference?

More info about collation is on docs:

The collation feature allows specifying the sort order and character classification (...)

like image 97
Michel Milezzi Avatar answered Oct 17 '22 04:10

Michel Milezzi