Re: enum bug

Поиск
Список
Период
Сортировка
От Melvin Davidson
Тема Re: enum bug
Дата
Msg-id CANu8FizZDXBY2fu7KNCJ5A8d67cKPvbyUajhah=8O6JhJQN2Rw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: enum bug  ("Joshua D. Drake" <jd@commandprompt.com>)
Список pgsql-general


On Mon, Mar 14, 2016 at 12:07 PM, Joshua D. Drake <jd@commandprompt.com> wrote:
On 03/14/2016 09:02 AM, David G. Johnston wrote:

​The one nice thing about enums is that you get two concepts in one
column - a human readable label and a system used ordering.

i.e., "SELECT enum_value FROM tbl ORDER BY enum_value" actually

​gives you a meaningful order without having to carry around, or relink
to, a lookup table to get an ordering column.

​Now, this is a bit overrated since you immediately lose that ability if
you export to a Spreadsheet program, or otherwise lose the ordering
nature during a convert-to-text operation.


I do not suggest that ENUMS are useless just that there are more flexible and reasonable ways (as a whole) to do what ENUMS provide.


Sincerely,

JD

--
Command Prompt, Inc.                  http://the.postgres.company/
                        +1-503-667-4564
PostgreSQL Centered full stack support, consulting and development.
Everyone appreciates your honesty, until you are honest with them.


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


It's not that hard to get all the valid enum values for a particular enum type.
Either of the queries below works just fine.

SELECT e.enumtypid,
       e.enumlabel,
       e.enumsortorder
  FROM pg_enum e
 WHERE e.enumtypid = {the enum oid}
 ORDER BY 1, enumsortorder;
 
SELECT e.enumlabel,
       e.enumsortorder,
       e.enumtypid
  FROM pg_type t
  JOIN pg_enum e ON e.enumtypid = t.oid
 WHERE t.typtype = 'e'
  AND t.typname = {the enum name}
 ORDER BY 1, enumsortorder;

However, IMHO, enums are archaic and Foreign Keys (Parent/Child) is the better way to go.
--
Melvin Davidson
I reserve the right to fantasize.  Whether or not you
wish to share my fantasy is entirely up to you.

В списке pgsql-general по дате отправления:

Предыдущее
От: "Joshua D. Drake"
Дата:
Сообщение: Re: enum bug
Следующее
От: Andrew Sullivan
Дата:
Сообщение: Re: enum bug