Supabase "operator does not exist: uuid = text" (42883) in an RLS or storage policy
Creating a policy, a migration, or calling an RPC fails with ERROR 42883 operator does not exist: uuid = text (or text = uuid, or uuid = jsonb). Your AI tool compared a uuid with text. How to find the mismatch, the cast that fixes it, and when to change the column instead.
Free · no card
Paste your error. Get a free diagnosis by email.
Tell us what broke and we’ll email you a short diagnosis: the likely cause and what to try first. Usually within a day.
What you are seeing
- Running a policy in the SQL Editor, or a migration the AI wrote, fails with
ERROR: 42883: operator does not exist: uuid = textandHINT: No operator matches the given name and argument types. You might need to add explicit type casts. - The same error reads
text = uuidwhen the sides are swapped, oruuid = jsonbfor a policy that reads team IDs out of the JWT. - A storage upload, download, or delete policy for "users can only touch their own files" will not save.
- A
supabase.rpc()call returns this error even though the function was created without complaint. - Your AI agent "fixed" it by turning RLS off or using
using (true). That removes the error and the protection.
Why it happens
auth.uid()returns auuid, but the column you compare it with istext(auser_idcreated as text). Postgres does not compare uuid and text without an explicit cast.- Storage helpers return text.
storage.foldername(name)returns an array of text, andstorage.objects.owner_idis text, so comparing either withauth.uid()fails. The olderownercolumn is a deprecated uuid, soowner = auth.uid()::textfails the other way round (Supabase issue #53833, opened Nov 23, 2026, reports this in a docs example). auth.jwt() ->> 'sub'is text, so comparing it with a uuid column fails withtext = uuid.auth.jwt() -> 'app_metadata' -> 'teams'is a singlejsonbvalue, not a list of uuids, soteam_id in (select ...)fails withuuid = jsonb(Supabase issue #53776, Nov 21, 2026).- A function parameter declared as
textis compared with a uuid column. The function is created fine and fails each time it runs.
How to fix it
1. Find the column types
select table_name, column_name, data_type
from information_schema.columns
where table_schema = 'public'
and (column_name = 'id' or column_name like '%\_id')
order by table_name, column_name;
-- a user_id / owner_id / author_id that says text while it holds user ids is the usual suspect
2. Quick fix: cast auth.uid() to text (not the column)
create policy "owner can read" on public.notes
for select to authenticated
using ( (select auth.uid())::text = user_id );
-- cast the auth.uid() side; casting the column (user_id::uuid) fails on any row that is not a valid uuid
-- and can stop Postgres from using an index on user_id
3. Lasting fix: make the column a uuid
-- 1. find rows that would break the conversion
select user_id from public.notes where user_id !~* '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$';
-- 2. drop the policies that use the column (Postgres refuses to alter it otherwise)
drop policy "owner can read" on public.notes;
-- 3. change the type, then recreate the policy without a cast
alter table public.notes alter column user_id type uuid using user_id::uuid;
create policy "owner can read" on public.notes
for select to authenticated
using ( (select auth.uid()) = user_id );
-- the ALTER rewrites and locks the table: run it in a quiet moment, after a backup
4. Storage policies: compare text with text
-- upload only into a folder named after the user: avatars/<user id>/file.png
create policy "own folder uploads" on storage.objects
for insert to authenticated
with check (
bucket_id = 'avatars'
and (storage.foldername(name))[1] = (select auth.jwt() ->> 'sub')
);
-- delete only your own files: use owner_id (text), not the deprecated owner (uuid)
create policy "delete own files" on storage.objects
for delete to authenticated
using ( owner_id = (select auth.uid()::text) );
5. Team IDs from the JWT: expand the array
create policy "team members" on public.projects
for select to authenticated
using (
team_id = any (
array(
select (jsonb_array_elements_text((select auth.jwt()) -> 'app_metadata' -> 'teams'))::uuid
)
)
);
-- app_metadata.teams must be an array of uuid strings, e.g. ["2222..."]
6. Functions: declare the parameter as uuid
create or replace function public.get_note(p_id uuid)
returns setof public.notes
language sql stable
as $$
select * from public.notes where id = p_id;
$$;
-- if you change a parameter's type, drop the old function first:
-- drop function public.get_note(text);
7. Tell your AI tool the rule
Add to your project rules (CLAUDE.md, .cursorrules, AGENTS.md, or Lovable knowledge): user id columns are uuid and reference auth.users(id); compare them with (select auth.uid()) with no cast; storage folder names and owner_id are text, so compare them with auth.jwt() ->> 'sub'; never fix a policy error by disabling RLS or using (true).
How to know it is fixed
The policy or migration runs without error. Then sign in as two different test users: each sees and can change only their own rows and files, and a signed-out request with the anon key returns nothing. In the dashboard, Advisors should not show RLS disabled on the table. Sources: Supabase: Row Level Security, Supabase: Storage access control, Supabase: Storage ownership (owner is deprecated, use owner_id), Supabase: Storage helper functions, supabase/supabase #53833, supabase/supabase #53776, PostgreSQL: type casts. Related: Supabase RLS not working, Supabase 42501 permission denied on a new table.