News for hackers. Stuff that matters.
Re:Cost of a Join by jaggederest on Tuesday August 14, 2018 @07:48PM (#17762851)
An enum is a relation, it's just a relation that is not stored in the same kind of table that other data is.

Your example is really a fairly poor strawman. I would suggest something more like a product with a "release date" column, which would be decomposed into a "releases" table with a foreign key. That's the kind of decomposition I've done a lot, and it's usually a useful one.

Another example would be having an "address" field, versus having number, street, apartment/suite, city, state, zip, country. I generally go with address data in a separate, relational table, instead of inline (user_addresses vs on the user table directly), and I've found that to be very useful at times.

In a lot of cases, you actually want a separate table (keyed on the real value, of course, not a generated foreign key) that stores things like zip codes or countries, because there is a lot of ancillary data to associate with them.

If you value homoiconicity, you want all your data to be in as similar a format as possible. Enums are a special case, and so you should avoid them unless you have a strong reason otherwise.

Re:Cost of a Join by mamcx on Tuesday August 14, 2018 @09:20PM (#17763181)
> An enum is a relation

This is TRUE. Most people ignore the relational model despite being so simple to learn. But one important thing to note, is that similar how you can say "anything is a object" you can say "anything is a relation".

This is valid SQL:

    SELECT * FROM (SELECT 1) a
And because "1" is a relation, a enum is.

Normal rdbms fail at operate to inner values (like the array feature on postgresql) and don't allow to put tables into cells. This is valid at the relational level but you need to do hacky stuff for common rdbms.

    SELECT Head =(SELECT * FROM INVOICE)
I'm working in a relational language, and this will be valid:

    for i in 1 do
and

    select value:Some(1).... where value.isSome
Re:Cost of a Join by krychu on Wednesday August 15, 2018 @12:43PM (#17767447)
Enums are not relations but data types as indicated in the first paragraph here: https://www.postgresql.org/docs/current/static/datatype-enum..., and by the related command ‘CREATE TYPE ...’.

Relations are commonly used when referring to tables and views.

What do you gain by calling types relations while introducing confusion and diminishing practicality of the relation concept?

Re:Cost of a Join by dragonwriter on Wednesday August 15, 2018 @03:49PM (#17769117)
Finite data types are, or are isomorphic to, (constant) relations, they aren't relvars like tables/views (relations include both constant relations and relvars.)

> What do you gain by calling types relations

The fact that everything true of other relations is true of finite types.

Re:Cost of a Join by mamcx on Wednesday August 15, 2018 @03:08PM (#17768798)
That is true. In postgresql.

Not int the relational model.

Re:Cost of a Join by talaketu on Wednesday August 15, 2018 @12:41AM (#17763807)
I don't buy "enum is a relation" any more than "VARCHAR is a relation" or "REAL is a relation". These just data types that represent the domain or range of possible values that may participate in a relation.
Re:Cost of a Join by mbrameld on Wednesday August 15, 2018 @02:35AM (#17764131)
> that represent the domain or range of possible values that may participate in a relation

Like a foreign key constraint?