Fix guides

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.

No passwords or secret keys, please. We only use your email to reply about this.

What you are seeing

Why it happens

  1. auth.uid() returns a uuid, but the column you compare it with is text (a user_id created as text). Postgres does not compare uuid and text without an explicit cast.
  2. Storage helpers return text. storage.foldername(name) returns an array of text, and storage.objects.owner_id is text, so comparing either with auth.uid() fails. The older owner column is a deprecated uuid, so owner = auth.uid()::text fails the other way round (Supabase issue #53833, opened Nov 23, 2026, reports this in a docs example).
  3. auth.jwt() ->> 'sub' is text, so comparing it with a uuid column fails with text = uuid.
  4. auth.jwt() -> 'app_metadata' -> 'teams' is a single jsonb value, not a list of uuids, so team_id in (select ...) fails with uuid = jsonb (Supabase issue #53776, Nov 21, 2026).
  5. A function parameter declared as text is 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.