On Mon, Mar 14, 2016 at 12:07 PM, Joshua D. Drake <jd@xxxxxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxx)
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.
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.