PostgreSQL ORDER BY Sort problem

Source: Internet
Author: User
Tags postgresql

The default sort is the order by field name,

This can be done if the field is not allowed to be empty.

However, when a field is allowed to be null, the way the order by field name causes:

Ascending (ASC):

Starts with the minimum value ascending, and the last polygon is connected to a value that has a null field value.

Descending (DESC):

Will put the null value as the maximum value in front, obviously this is not the sort result we want.

PostgreSQL offers NULLS first | the last keyword of the ORDER by clause can satisfy the need

... ORDER by last_updated NULLS first
SELECT last_updated      0 1 END,          last_updated ASC;

PostgreSQL ORDER BY Sort problem

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.