Changes between Version 5 and Version 6 of DatabaseProgramming


Ignore:
Timestamp:
06/08/26 22:36:11 (10 days ago)
Author:
231116
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DatabaseProgramming

    v5 v6  
    143143    $$ language plpgsql;
    144144}}}
    145 == Check if a room is available
    146 {{{
    147 create or replace function fn_is_room_available(p_room_id bigint,p_check_in_date date, p_check_out_date date)
    148 returns boolean
    149 language plpgsql
    150 as $$
    151     begin
    152         if p_check_in_date >= p_check_out_date then
    153             return false;
    154         end if;
    155 
    156         if not exists(
    157             select 1
    158             from rooms r
    159             where r.room_id = p_room_id
    160             and r.status = 'ACTIVE'
    161         )then
    162             return false;
    163         end if;
    164 
    165         if exists(
    166             select 1
    167             from bookings b
    168             where b.room_id = p_room_id
    169             and b.booking_status in ('PENDING','CONFIRMED')
    170             and daterange(b.check_in_date,b.check_out_date,'[)')
    171             && daterange(p_check_in_date,p_check_out_date,'[)')
    172         )then
    173             return false;
    174         end if;
    175         return true;
    176     end;
    177     $$;
    178 }}}
     145
    179146== Create timestamp
    180147{{{
     
    284251            raise exception 'Check out must be after check in';
    285252        end if;
    286         v_nights := p_check_in_date - p_check_out_date;
     253        v_nights := p_check_out_date - p_check_in_date;
    287254        if p_guest_count > v_capacity + v_extra_capacity then
    288255            raise exception 'Guest count exceeds';