Only INSERT if reservation doesn't exist yet.

Hey guys, I am doing a policy to prevent a user from "double" booking a listing, and I am wondering if the following WITH CHECK is valid or if it's efficient.

Conditions = Check if the authenticated user reserved_by already booked the existing listing_id


WITH CHECK (auth.uid() = reserved_by 
AND NOT EXISTS 
    ( select 1 from reservations where       
listing_created_by = listing_created_by));
Was this page helpful?