News for hackers. Stuff that matters.
Re:Against SQL by laszlokorte on Saturday July 10, 2021 @08:56AM (#27793053)
Thinking a bit more about it I think this would be a very elegant solution for Tagged-Unions in SQL:

- simply allow tagged unions for foreign key constraints: CONSTRAINT my_fk FOREIGN KEY (own_column) REFERENCES EITHER table_a (a_id) OR table_b (b_id) OR table_c (c_id)

- add join syntax to join via defined foreign key: FROM own_table JOIN VIA my_fk

The union FK would store an additional flag determining the target table and the JOIN VIA would switch on that flag and it would be allowed to use any columns from all target tables in the query but only the matching ones would be not null.

Re:Against SQL by goto11 on Saturday July 10, 2021 @10:29AM (#27793553)
If you put the foreign keys on the table_a/b/c tables, then you can express the same without having to introduce tagged unions.
Re:Against SQL by laszlokorte on Saturday July 10, 2021 @10:34AM (#27793585)
As I said in response to a sibling: But can you can not (in a simple way) prevent that both a circle and a triangle point to the same user and you can not enforce a NOT NULL for a user to must have a favourite shape.