Skip to main content
NikoFischer.com

Main navigation

  • Home
  • About
    • My Reading List
    • Recommended Youtube Channels
    • Life Rules
    • Podcast
  • 50-Day Challenge
  • Impressum
Sprachumschalter
  • English

Breadcrumb

  1. Home

Supabase throws "new row violates row-level security policy for table" even though I had created a row level policy for inserts

🎸
🚀 Beta Running

PYNGUP: Rebellion against toxic productivity

Beta limited to 100 spots. Tasks become social commitments instead of lonely to-dos.

🚀 Join Beta 📖 Read Story "€487 wasted"
By Niko, 19 July, 2021

I was confronted with a Supabase problem that (almost) drove me crazy: I have a simple table "projects" that only stores a project uuid and a project name. While developing on my Web-App I disabled role level security (RLS) for this table. I usually proceed disabling row level policies in the first phase of developing as it helps me to focus on the frontend and the general project scheme.

Inserting data in the table throws a row-level security alert

As I enabled row-level security on my "projects" table and trying to insert new data I received the following error:

new row violates row-level security policy for table "projects"

This is how my policy looks like:

Supabase row level security policy

This is a simple rule that checks if the user is authenticated while inserting new data. I took the rule from the example rules provided by the Supabase Team itself.

Solution: Add a SELECT policy

I found out that Supabase (or Postgres?) seems to not only INSERT the data you provide but also directly tries to SELECT it. So if you don't have a SELECT policy also the INSERT process fails.

In my case this is not quite easy to solve: I have another table called project_members where I reference all users that are related to the project. So at first time when inserting new data to the projects table there is no data in the project_members table. This leads to a situation where the SELECT policy for my projects table always fails on the first INSERT.

But fortunately there is another way:

Solution 2: Modify insert statement

Just add { returning: 'minimal' } to your insert statement. This suppresses the direct selection of the added data. The complete statement looks like this:

await supabase.from('sample').insert({ key: 'value' }, { returning: 'minimal' })

This works perfectly!

Tags

  • Supabase
  • Add new comment

Comments2

About text formats

Restricted HTML

  • Allowed HTML tags: <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Royal VICTOR (not verified)

1 year 2 months ago

Thanks !!

This bug drives me crazy too and I spent a lot of time before discovering your article !
Nice job ! Thank you !!

  • Reply

Lautixon (not verified)

1 year ago

Thanks😊

This worked perfectly

  • Reply

Related articles

Supabase: How to query users table?
Supabase vs. Firebase - Unveiling the Differences
Supabase Edge Functions CORS Error Fix - Complete Guide 2025
Supabase Storage: How to Implement File Upload Properly
Building a ChatGPT Clone with Supabase Edge Functions and OpenAI

About the author

Nikolai Fischer is the founder of Kommune3 (since 2007) and a leading expert in Drupal development and tech entrepreneurship. With 17+ years of experience, he has led hundreds of projects and achieved #1 on Hacker News. As host of the "Kommit mich" podcast and founder of skillution, he combines technical expertise with entrepreneurial thinking. His articles about Supabase, modern web development, and systematic problem-solving have influenced thousands of developers worldwide.

Ihre Anmeldung konnte nicht gespeichert werden. Bitte versuchen Sie es erneut.
Ihre Anmeldung war erfolgreich.

Newsletter

Join a growing community of friendly readers. From time to time I share my thoughts about rational thinking, productivity and life.

Nikolai Fischer

✌ Hi, I'm Niko
Entrepreneur, developer & podcaster

Contact me:

  • E-Mail
  • Phone
  • LinkedIn

My Reading List

  • $100M Leads: How to Get Strangers To Want To Buy Your Stuff - Alex Hormozi
  • Quantitative Trading: How to Build Your Own Algorithmic Trading Business (Wiley Trading) - Ernest P. Chan
  • Hands-On Machine Learning for Algorithmic Trading: Design and implement investment strategies based on smart algorithms that learn from data using Python - Stefan Jansen
  • Algorithmic Trading - Ernie Chan
  • Let Me Tell You a Story: Tales Along the Road to Happiness - Jorge Bucay
more
RSS feed