Re: string_agg distinct order by

From: Michael Lewis <mlewis(at)entrata(dot)com>
To: "Markhof, Ingolf" <ingolf(dot)markhof(at)de(dot)verizon(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: string_agg distinct order by
Date: 2021-08-20 00:03:40
Message-ID: CAHOFxGq7x_vn53+JAjjr=ZaLoHvgY+BGev5wZLnZnwugjvQzwQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

https://www.postgresql.org/docs/current/datatype-enum.html

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*

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Lucas 2021-08-20 01:33:09 Re: PostgreSQL 9.2 high replication lag
Previous Message Michael Lewis 2021-08-19 23:58:03 Re: Regexp_replace bug / does not terminate on long strings