Re: Sorting distinct dates by year and month respectively - Mailing list pgsql-novice

From Tom Lane
Subject Re: Sorting distinct dates by year and month respectively
Date
Msg-id 29995.1149692180@sss.pgh.pa.us
Whole thread Raw
In response to Sorting distinct dates by year and month respectively  ("Matt Arnilo S. Baluyos (Mailing Lists)" <matt.baluyos.lists@gmail.com>)
List pgsql-novice
"Matt Arnilo S. Baluyos (Mailing Lists)" <matt.baluyos.lists@gmail.com> writes:
> ... ORDER BY date_part('year', article_pubdate),
> date_part('month', article_pubdate) DESC;

The above means

    ... ORDER BY date_part('year', article_pubdate) ASC,
    date_part('month', article_pubdate) DESC;

You want

    ... ORDER BY date_part('year', article_pubdate) DESC,
    date_part('month', article_pubdate) DESC;

As noted by the other respondent, sorting on one date_trunc column is
probably the better way to do it, but I thought I'd point out the DESC
issue anyway.  A lot of people get that wrong.

            regards, tom lane

pgsql-novice by date:

Previous
From: Arnaud Lesauvage
Date:
Subject: Re: levenshtein contrib installation
Next
From: Richard Broersma Jr
Date:
Subject: Re: Sorting distinct dates by year and month respectively