Adam
Adam
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Adam on 11/22/2023 in #questions
Tagged Union in a Relational Database
really specific question, how does one represent a tagged union in a relational database? take the following typescript type as an example:
type TaggedUnionTable = {
id: string;
} & (
| {
type: 'tag_a';
specific_info_to_tag_a: object;
}
| {
type: 'tag_b';
specific_info_to_tag_b: object;
}
);
type TaggedUnionTable = {
id: string;
} & (
| {
type: 'tag_a';
specific_info_to_tag_a: object;
}
| {
type: 'tag_b';
specific_info_to_tag_b: object;
}
);
I implemented it in postgresql using jsonb type, but there has to be a better option. (answer with sql pls)
5 replies