PostgreSQL case sensitivity sorting

Source: Internet
Author: User

Create the following table in PostgreSQL and insert the following data:

Create Table "TTT "(

Id varchar (32) primary key not null,

Name varchar (128) not null

);

Create unique index ttt_name_idx on "TTT" (name );

Insert into "TTT" values ('1', 'A ');

Insert into "TTT" values ('2', 'A ');

Insert into "TTT" values ('3', 'B ');

Insert into "TTT" values ('4', 'B ');

If you execute

Select * from "TTT" order by name;

The following result is displayed:

Id | Name

---------- + ------------

2 |

1 |

4 | B

3 | B

(4 rows)

Here we expect the name to be sorted first by uppercase letters and then by lowercase letters.

 

After checking the information, you can solve the preceding sorting problem through the following operations:

1. First, back up the database configuration file and data file (preferably export data). By default, it is all the data in the/var/lib/pgsql/data directory.

2. $ sudo/etc/init. d/PostgreSQL stop

3. $ sudo Su-Postgres

# Initdb -- LC-collate = C

4. $ sudo/etc/init. d/PostgreSQL start

5. Execute the following query again

Select * from "TTT" order by name;

The result is as follows:

Id | Name

---- + ------

1 |

3 | B

2 |

4 | B

(4 rows)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.