© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
10 replies
Rozko

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
reserved_by
already booked the existing
listing_id
listing_id



WITH CHECK (auth.uid() = reserved_by 
AND NOT EXISTS 
    ( select 1 from reservations where       
listing_created_by = listing_created_by));
WITH CHECK (auth.uid() = reserved_by 
AND NOT EXISTS 
    ( select 1 from reservations where       
listing_created_by = listing_created_by));
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Snippet doesn't exist
SupabaseSSupabase / help-and-questions
6mo ago
Only insert nullable column if not null
SupabaseSSupabase / help-and-questions
4y ago
How to know if a public url doesn't exist?
SupabaseSSupabase / help-and-questions
3y ago
connection string host doesn't exist.
SupabaseSSupabase / help-and-questions
2d ago