I am looking for a way to establish the relationship between one and two between two tables. The table structures are described below, but I tried to leave everything that has nothing to do with the problem.
The objects table has 1 column named uuid .
The contents table has 3 columns called content , object_uuid and timestamp .
The main idea is to insert a string in objects and get a new uuid from the database. This uuid then used for each line in contents to bind content to objects.
Now I am trying to use a database to provide this:
- Each line in
contents refers to a line in objects (a foreign key must be executed) - No row in
objects exists, at least row in contents
These restrictions must be observed when making transactions.
Ordinary triggers cannot help, because when a row is written in the objects table, there cannot be a row in contents . Postgres has so-called constraint triggers , which can be delayed until the end of the transaction. You could use them, but they seem to be a kind of internal structure, not intended for everyday use.
Ideas or solutions should be standard SQL (preferred) or work with Postgres (version doesn't matter). Thanks for any input.
source share