Я думаю, вы можете начать с этого, быстро и грязно
create table default_limit (id int,location int, "limit" int );
create table daily_limit (id int,location int, "limit" int, dt date );
create table reserved (id int,location int, quantity int, dt date );
insert into default_limit(id,location,"limit") values (1,1,5);
insert into default_limit(id,location,"limit") values (2,1,5);
insert into daily_limit(id,location,"limit",dt) values (1,1,3,'10/21/18'::DATE);
insert into reserved(id,location,quantity,dt) values (1,1,1,'10/21/18'::DATE);
create or replace function q(p_id int,p_location int,p_quantity int, p_dt date)
RETURNS boolean
as $$
select
coalesce(
(p_quantity + coalesce(l3.quantity,0))
<=
coalesce(l2."limit",l1."limit",2147483647)
,true)
from
(select * from default_limit where id = p_id
and location = p_location
limit 1) l1
full join
(select * from daily_limit where id = p_id
and location = p_location
and dt = p_dt
limit 1) l2
on true
full join
(select * from reserved where id = p_id
and location = p_location
and dt = p_dt
limit 1) l3
on true
full join (select 1 as p) ph on true
$$ language sql;
select q(1,1,1,'10/21/18'); -- true
select q(1,1,2,'10/21/18'); -- true
select q(1,1,3,'10/21/18'); -- false
select q(3,4,42,'10/22/18'); -- true