Re: string_agg distinct order by - Mailing list pgsql-general

From Michael Lewis
Subject Re: string_agg distinct order by
Date
Msg-id CAHOFxGq7x_vn53+JAjjr=ZaLoHvgY+BGev5wZLnZnwugjvQzwQ@mail.gmail.com
Whole thread Raw
In response to string_agg distinct order by  ("Markhof, Ingolf" <ingolf.markhof@de.verizon.com>)
List pgsql-general
I believe that you could define an enumerated type to use for those status colors such that the ordering is defined as you like without two separate columns for the name and sort_value or whatever.



Example in the documentation expanded a little to demonstrate-

CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');

CREATE TABLE person (
    name text,
    current_mood mood
);
INSERT INTO person VALUES ('Moe', 'happy');
INSERT INTO person VALUES ('Joe', 'sad');
INSERT INTO person VALUES ('Roe', 'ok');

SELECT * FROM person order by current_mood;
SELECT * FROM person order by current_mood desc;

Note- using enum may complicate other things in your usage, so I am not suggesting this is ideal, just one option.


Michael Lewis  |  Database Engineer
Entrata

pgsql-general by date:

Previous
From: Michael Lewis
Date:
Subject: Re: Regexp_replace bug / does not terminate on long strings
Next
From: Lucas
Date:
Subject: Re: PostgreSQL 9.2 high replication lag