Re: enum bug

From: Melvin Davidson <melvin6925(at)gmail(dot)com>
To: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Elein <elein(at)varlena(dot)com>, GENERAL <pgsql-general(at)postgresql(dot)org>
Subject: Re: enum bug
Date: 2016-03-14 16:09:32
Message-ID: CANu8FizZDXBY2fu7KNCJ5A8d67cKPvbyUajhah=8O6JhJQN2Rw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Mar 14, 2016 at 12:07 PM, Joshua D. Drake <jd(at)commandprompt(dot)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(at)postgresql(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Sullivan 2016-03-14 16:43:43 Re: enum bug
Previous Message Joshua D. Drake 2016-03-14 16:07:48 Re: enum bug