I'm setting up a database for a computer store. In the database I have a table called computer_system, which has an array attribute. In the array these components go: cpu ram case mainboard graphics card
Now to the tricky part: The different components have their own tables and are all child tables of a table called component. The mainboard table has an attribute called "on-board graphics". If it has a graphics card, it will be listed here. If not, the attribute is null.
Now, when I insert components in the computer_system table, I need postgres to check if the mainboard passed in, has an on_board graphics card. If not, a graphics card must be added, before the query can execute succesfully. How do I add this constraint?
I tried to explain my issue the best that I can, and I have checked all my books, but I cannot find the answer to this. Feel free to ask me, if something was unclear. Also, here is an unfinished ER-diagram I've made for this database
https://i.sstatic.net/zAT0f.png
EDIT: In other words what I want to do is, if mainboard.on_board_graphics is NULL, then graphics_card cannot be NULL.
mainboard.graphics_card_id references graphics_card(id). Then you can add constraintcheck ((on_board_graphics is not null) or (graphics_card_id is not null)).sqlfiddleis very stupid. Take a look at this paste. The problem solved with trigger.