Security basics
Supabase "operator does not exist: uuid = text" in a policy
Supabase "operator does not exist: uuid = text": auth.uid() is a uuid and your column is text. Make them match, and never loosen the policy.

In short
- Supabase "operator does not exist: uuid = text" (Postgres code 42883) means a policy compares auth.uid(), which returns a uuid, with a column stored as text. Postgres has no = for that pair, so the policy is never created.
- If the column holds Supabase user ids, change it to uuid, or write (select auth.uid())::text = user_id. If it holds ids from Clerk or another sign-in service, compare auth.jwt() ->> 'sub' instead.
- Do not make the policy save by taking the comparison out. using (true) passes every row to every visitor the policy names, and Supabase's guide says to use it only for data that is meant to be public.
You asked your builder to make sure each customer sees only their own orders. It wrote a policy, ran it, and the migration stopped with this:
ERROR: operator does not exist: uuid = text
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
Supabase "operator does not exist: uuid = text" means Postgres was asked to
compare two values of different types, a uuid and a piece of text, and it has no
rule for comparing those two. So it refused, and the policy was never created.
In a policy written as auth.uid() = user_id, the uuid is auth.uid(), the
signed-in user's id, and the text is your user_id column.
There are two ways to make the message go away. Make both sides the same type,
and the policy compares ids the way you meant it to. Take the comparison out, as
in using (true), and the policy saves because it no longer compares anything:
every row passes, for every visitor the policy applies to.
What does "operator does not exist: uuid = text" mean?
It means Postgres found no = that takes a uuid on one side and text on the
other, so it stopped before running the statement. Nothing was created and no
row changed.
A uuid is an id in one fixed shape: 32 characters from 0 to 9 and a to
f, in five groups, such as 3f2b8c1e-9a4d-4e7b-b1c2-5d6e7f8a9b0c. Text is any
characters at all. Postgres keeps them as separate types and will not decide by
itself that a piece of text was meant as an id. Its
page on casts
puts it this way: "The automatic casts to string types are treated as assignment
casts, while the automatic casts from string types are explicit-only." In
practice, Postgres turns a uuid into text when you store one in a text column,
turns text into a uuid only when you ask, and inside a comparison does neither.
Picture the policy as a guard at the door of the table, checking each row
against the visitor. auth.uid() hands the guard the visitor's pass, with the
id printed on it. Your user_id column has each row's owner written in by hand.
The guard will not hold a printed pass against handwriting and decide the two
look alike, so it turns the job down.
| Part | What you see | What it tells you |
|---|---|---|
| Message | operator does not exist: uuid = text | The type on the left of =, then the type on the right. In auth.uid() = user_id, the left is auth.uid() |
| Code | 42883 | Postgres's code for this error, named undefined_function in its list of codes |
| Hint | You might need to add explicit type casts. | Postgres's own advice: convert one side, so both are the same type |
| Swapped | operator does not exist: text = uuid | The same error with the column written first, as in user_id = auth.uid() |
auth.uid() reads the user id out of the visitor's sign-in token and converts
it to a uuid before returning it, as
its definition
shows. So the column it is compared with has to be a uuid as well, or the
comparison has to be made as text on purpose.
If Row Level Security is already on for that table and this was to be its first policy, the table has no policy at all yet. Postgres's documentation calls that a "default deny" policy, "so that no rows will be visible or updatable". Your app shows empty lists to everyone, the people the rows belong to included.
The same message turns up anywhere a uuid meets text: a policy that looks the
visitor up in another table, such as members.user_id = auth.uid(), a join
between a uuid profiles.id and a text user_id, or a function that does
either.
To see which type your column is, run this in the SQL Editor, with your own
table's name in place of orders:
select column_name, data_type
from information_schema.columns
where table_schema = 'public'
and table_name = 'orders'
and column_name = 'user_id';
text in the second column confirms it. Then look at a few values with
select user_id from public.orders limit 5;. Ids in the five-group shape are
Supabase user ids saved as text. Ids such as user_2abc… come from Clerk, which
keeps its ids as text by design. Which of the two you see decides the fix.
Why not loosen the policy until it saves?
Because a policy that saves without comparing ids lets everyone it names read
every row. Postgres's rule for the using part of a policy is that "Rows for
which the expression returns true will be visible", and true is true for every
row.
Each way of taking the comparison out opens the table to a different group:
| The policy that saves | Who can then read every row |
|---|---|
to anon using (true) | every visitor who is not signed in, with the publishable key your app already gives them |
to authenticated using (true) | every signed-in user, which on an app with open sign-up is anyone who makes an account |
using (auth.uid() is not null) | the same: every signed-in user |
Supabase's own
guide to Row Level Security
shows using ( true ) for a profiles table that everybody may read, and says of
it: "Use it only for data that is meant to be public." Orders, messages and
anything else that belongs to one person are not that. On the door, a true
policy sends the guard home.
Switching Row Level Security off for the table makes the error go away as well, because no policy is checked at all. Switching it on for every table covers how to turn it back on and prove that it holds.
How do I fix "operator does not exist: uuid = text"?
Make both sides the same type. What your user_id column holds tells you which
of three ways to do it:
What user_id holds | The fix | What changes |
|---|---|---|
| Supabase user ids, and you want the smallest change today | Cast auth.uid() to text in the policy | One line of the policy |
| Supabase user ids, and you want it right for good | Change the column to uuid | The column's type, and the policy is written as auth.uid() = user_id |
| Ids from Clerk or another sign-in service | Compare auth.jwt() ->> 'sub' | One line of the policy. auth.uid() cannot read those ids |
Cast auth.uid() to text
Convert the side that is always a uuid. Postgres writes a uuid out in one fixed
form, so auth.uid() turned into text gives the same characters every time:
create policy "Customers read their own orders"
on public.orders for select
to authenticated
using ( (select auth.uid())::text = user_id );
::text is Postgres's short way to write a cast. The (select …) around
auth.uid() is the form Supabase's guide recommends inside a policy, because it
lets Postgres work the value out once per query rather than once per row. On a
large table, a function called for every row is one way a read
runs out of time.
A policy that lets people add or edit rows needs the same cast in its
with check line, the half that judges new rows
(what with check does), or it
stops with the same error.
This matches only ids saved the way Postgres writes them. Its
documentation on the uuid type
says the output "is always in the standard form": lower-case letters, in groups
of 8, 4, 4, 4 and 12. A user_id saved in capitals or without its dashes is
still the same id to a person, but as text it is a different string, and that
row is hidden from its own owner. This lists any row saved another way:
select user_id
from public.orders
where user_id !~ '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$';
No rows back means every id is in the form the cast produces.
The cast can go on the other side, auth.uid() = user_id::uuid, and the policy
saves that way too. Then Postgres converts every row's user_id as it reads it,
and one value that is not a uuid, a test row or an empty string, stops the
whole read with
invalid input syntax for type uuid,
for every visitor whose read reaches that row. On the door, the guard now has to
reprint each handwritten name as a pass before checking it, and the first name
that will not print stops the queue.
Change the column to uuid
If every value is a Supabase user id, give the column the type it holds. Then
auth.uid() = user_id compares like with like, and Postgres refuses any new
value that is not written as a uuid before it is saved.
Postgres will not change the type of a column that a policy uses. It stops with
cannot alter type of a column used in a policy definition and a detail line
naming the policy. So the change is three steps: drop the policies that mention
the column, change the type, and create the policies again.
First list the table's policies and copy any that mention user_id:
select policyname, cmd, qual, with_check
from pg_policies
where schemaname = 'public' and tablename = 'orders';
qual is each policy's using rule and with_check its with check rule.
Then run the three steps together, between begin and commit:
begin;
drop policy "Customers read their own orders" on public.orders;
alter table public.orders
alter column user_id type uuid using user_id::uuid;
create policy "Customers read their own orders"
on public.orders for select
to authenticated
using ( (select auth.uid()) = user_id );
commit;
Four things can stop it:
- No
usingclause. Withoutusing user_id::uuid, Postgres answerscolumn "user_id" cannot be cast automatically to type uuid, and its hint is that same clause. - A default written as text. A column with a default such as
auth.uid()::textstops the change withdefault for column "user_id" cannot be cast automatically to type uuid. Addalter table public.orders alter column user_id drop default;before the change andalter table public.orders alter column user_id set default auth.uid();after it. - A value that is not a uuid. The change stops with invalid input syntax for
type uuid and quotes the value. Because everything runs between
beginandcommit, nothing is altered, the dropped policies included. The query in the section above lists the rows to look at first. - A policy you did not drop. The detail line names it. Add it to the block and run it again.
Postgres rewrites the whole table and its indexes to change a column's type,
says its
page on ALTER TABLE,
and while it does, it holds the lock that, in its own words, "guarantees that
the holder is the only transaction accessing the table in any way". Your app's
reads of that table wait until the commit. On a table with many rows, run it
when few people are using the app, and
make a copy of the database first, because
every row of the table is written again.
If you build by prompting, ask for it in one sentence: "Change orders.user_id to uuid in one migration: drop the policies that use it, alter the column using user_id::uuid, and create the same policies again with (select auth.uid()) = user_id."
When the ids come from Clerk or another sign-in service
Keep the column as text and compare it with the user id from the sign-in token,
also as text: auth.jwt() ->> 'sub'.
auth.uid() converts the token's id to a uuid, and Clerk's ids, which start with
user_, are not uuids. So a policy that calls auth.uid() for a Clerk user
fails with invalid input syntax for type uuid.
Clerk's guide to Supabase
keeps user_id as text, with default auth.jwt()->>'sub', and writes its
policies to match:
create policy "Customers read their own orders"
on public.orders for select
to authenticated
using ( (select auth.jwt() ->> 'sub') = user_id );
auth.jwt() returns the claims in the visitor's sign-in token, and ->> 'sub'
takes the user id out of them as text. Both sides are text, and nothing needs
converting.
How do I test the policy as a user?
Run the read as a signed-in user inside a transaction, then roll it back. Supabase's guide tests policies this way, by switching the role and the user's identity for the length of the transaction. Copy a real user id from Authentication → Users in your dashboard:
begin;
set local role authenticated;
set local request.jwt.claims to '{"role":"authenticated", "sub":"PASTE-A-USER-ID"}';
select * from public.orders;
rollback;
auth.uid() and auth.jwt() both read the user id from request.jwt.claims,
so this works for every policy in this post. Run it with two different users:
each should get only their own orders. Then write set local role anon;, leave
out the claims line, and a private table should give back no rows at all.
That shows what your rules do for a signed-in user. What your live app hands to a visitor with no login can be seen from outside. Our free scan asks each table your app's code names how many rows that visitor can count, reads only the number, and takes about 20 seconds with no account. Scan your app.
Keeping the rows private after the next migration
A policy can change every time you or your builder run a migration, and a type change like the one above writes every row of the table again. Two things keep an eye on it afterwards:
Reeve Monitor keeps checking from outside:
- the full security check every hour, including how many rows a visitor with no login can count in the tables your app reads
- whether your app answers, every 60 seconds, and up to 10 more pages you choose
- an alert by email, Telegram, Slack or webhook when the app goes down or a page breaks
- a monthly report on your app, written for you
Reeve Care keeps a copy of your Supabase database:
- an encrypted copy on a schedule, on Reeve's own storage in the EU, outside your Supabase account
- the last copy before you change a column's type holds the table as it was, rows included
- each copy verified before it counts, by counting the rows in every table
- your uploaded files as well, once you connect a Storage credential
- a one-click restore, with a safety copy of the current state taken first
- everything Monitor does
The free scan shows what a visitor with no login can count in your tables today. About 20 seconds, and no account.
Scan your app free in 20 seconds
What to do now
What to do
- Read the two types in the message. The first is the left side of your
=. - Check what
user_idholds: Supabase ids in five groups, or ids such asuser_…from Clerk. - For Supabase ids, change the column to
uuidin one transaction, or write(select auth.uid())::text = user_id. - For Clerk ids, write
(select auth.jwt() ->> 'sub') = user_id. - Never make a policy save with
using (true)orauth.uid() is not nullon a table that holds people's own rows. - Test the policy as two users and as
anonbefore you rely on it.
Start with the column's type, because it decides which fix is right. If you change it, keep a copy of the database from before the change.
FAQ
What does operator does not exist: uuid = text mean?
It means Postgres was asked to compare a uuid with a piece of text and has no = for that pair, so it refused the statement before running it. In a Supabase policy written as auth.uid() = user_id, auth.uid() returns a uuid and the user_id column is text. The code is 42883, and the policy was not created.
Should I cast auth.uid() or the column?
Cast auth.uid(), as in (select auth.uid())::text = user_id. Casting the column, user_id::uuid, converts every row as Postgres reads it, and one value that is not a uuid makes the read fail with invalid input syntax for type uuid. If every value in the column is a Supabase user id, changing the column to uuid is the lasting fix.
Can I use using (true) to make the policy save?
It saves because it no longer compares anything, so every row passes for every visitor the policy names. Supabase's guide shows it for a table everybody may read and says to use it only for data that is meant to be public. For a table of people's own rows, make the two types match instead.
How do I change a Supabase column from text to uuid?
In one transaction: drop the policies that mention the column, run alter table … alter column user_id type uuid using user_id::uuid, then create the policies again. Postgres will not change the type of a column a policy uses, and the using clause tells it how to convert the values. A value that is not a uuid stops the change, and nothing is altered.
Why does auth.uid() fail with Clerk user ids?
Because auth.uid() converts the user id in the sign-in token to a uuid, and Clerk ids, which start with user_, are not uuids. Keep the column as text and compare (select auth.jwt() ->> 'sub') = user_id, which is how Clerk's own Supabase guide writes its policies.