I personally don't like the idea of pushing the Job.ID value on all the other child tables
Why not? The obvious solution is to make JobID the leading PK/clustered index column on all the child tables. And it ensures optimal performance for accessing all these tables by JobID.
Generally whenever you have an "identifying relationship" aka "child table" aka ...
An example of how data integrity can be maintained using FKs.
I have modified the model a bit to allow for an executable to be a part of more than one job. The assumption is that when an executable runs, it runs for all customers associated with that executable. Your ERD does not show constraints, so there is some guessing involved.
-- Customer CUS exists....
I had just asked that on a different forum. The best solution for a 3rd Normal Form schema design was to select all that is needed in the linking table and compare the Cardinality (count) of the matching results.
The other forum was for Oracle. The answer you seek is the PostgreSQL version of this post: https://community.oracle.com/message/15613817#...
Here's another approach:
SELECT @usa := country_id from countries where iso_alpha3_code = 'USA';
insert into provinces (province_name, country_id)
But I contend that you should not normalize country_code; simply use the standard 3-letter (or 2-letter) codes.
The savings ...
Try this one
with cte as (
select metric_id, value, datetime, ROW_NUMBER () OVER (PARTITION BY metric_id ORDER BY datetime desc) as rn
select n.ip, m.id, m.key, m_h.value, m_h.datetime
from metric as m
join node as n on m.node_id = n.id
join cte as m_h on m.id = m_h.metric_id and m_h.rn=1