© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago
LufyCZ

Checking for counts in RLS

Hey, I've got a table with 3 rows (which matter)

ID = PK
user_id=uuid
lesson=int

I want a user to only be allowed to create a new row if they don't have that specific lesson yet. (+ they can only create a row for their user_id)

This can't happen:
id: 1; user_id=1; lesson=1
id: 2; user_id=1; lesson=1

This can happen:
id: 1; user_id=1; lesson=1
id: 2; user_id=1; lesson=2

I've currently got this in the CHECK part:
((SELECT count(*) AS count
   FROM "lectureSeats" "lectureSeat"
  WHERE (("lectureSeat".user_id = uid()) AND ("lectureSeat".lecture = 1))) <= 1)
((SELECT count(*) AS count
   FROM "lectureSeats" "lectureSeat"
  WHERE (("lectureSeat".user_id = uid()) AND ("lectureSeat".lecture = 1))) <= 1)


Problem is, I can't seem to get the
("lectureSeat".lecture = 1)
("lectureSeat".lecture = 1)
part right, when I try
("lectureSeat".lecture = lecture)
("lectureSeat".lecture = lecture)
it just replaces it with
("lectureSeat".lecture = "lectureSeat".lecture )
("lectureSeat".lecture = "lectureSeat".lecture )
which is of course always true and doesn't work.

How do I get that newRow.lecture in there?

Thanks
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

RLS for Columns?
SupabaseSSupabase / help-and-questions
3y ago
Using RLS for CLS
SupabaseSSupabase / help-and-questions
6mo ago
rls
SupabaseSSupabase / help-and-questions
4y ago
RLS
SupabaseSSupabase / help-and-questions
4y ago