Fix guide · updated 2026-11-16
Supabase "value too long for type character varying" (22001)
{"code":"22001","details":null,"hint":null,"message":"value too long for type character varying(255)"}
An insert or update from your app fails with "value too long for type character varying(255)", code 22001, HTTP 400. A column has a length limit and one value in the row is longer. The message gives the limit but not the column, so the first job is finding it. We reproduced the usual ways it happens with the request code of supabase-js 2.119 against Postgres 16, Supabase's Data API (PostgREST 13) and Supabase Storage, November 2026.
What the error means
A column of type varchar(255), also written character varying(255), holds at most 255 characters. A longer value is refused and nothing is written. The number in the message is the column's limit, not the length of what you sent. For a char(2) column, the same error reads "value too long for type character(2)".
The message names neither the table nor the column, and details and hint are empty. In our test that was true for a signed-in user with row level security (RLS) on and for the service role key alike.
In Postgres, a limit like 255 doesn't make anything faster. The Postgres documentation says there is no performance difference between text and varchar(n), and suggests text when there is no real upper limit. Generated schemas still often use varchar(255), varchar(50) or varchar(20), a habit from other databases.
Cause 1: text longer than the column
Names, bios and titles that people type. In our test, username varchar(20) refused "the_real_alexandra_smith" (24 characters), full_name varchar(50) refused a 55-character full name, and bio varchar(255) refused a 324-character bio, in an insert, an update and an upsert alike.
Cause 2: a URL or another value the app makes
Signed Storage URLs are the classic case. In our test, createSignedUrl() for avatars/<user id>/avatar.png returned a 349-character URL, and saving it into avatar_url varchar(255) failed. The public URL of the same file (121 characters) and the file path (47) both fit. Tokens and images saved as text are long too.
Cause 3: a code longer than a short column
Short fixed columns break on the first longer code. In our test, country char(2) refused 'USA' with "value too long for type character(2)". Postal codes with a space or a dash, phone numbers with a + and spaces, and full country names do the same in a column sized for the short form.
Cause 4: the column is in another table
If none of your table's columns has the limit from the message, a trigger is writing somewhere else. In our test, posts.title was text, but a trigger copied "New post: " and the title into activity.summary varchar(50). Inserting a 44-character title failed with "value too long for type character varying(50)", on the insert into posts. The second query in the one-minute check finds that column.
During sign-up, the same thing in the trigger that creates each profile shows up as "Database error saving new user": see Database error saving new user (Supabase).
Cause 5: a migration that makes a column shorter
This one comes from a migration or the SQL Editor: changing full_name to varchar(10) failed with "value too long for type character varying(10)" because an old row held "Ana Martins" (11 characters). Nothing changed. Fix 5 finds those rows.
Things that surprise people
- When several columns share the limit, the message can't tell them apart. In our test, the long bio and the long signed URL both failed with "character varying(255)".
- The limit counts characters, not bytes. In our test, 20 thumbs-up emoji fit in
varchar(20), though JavaScript's.lengthcounts them as 40. A.lengthcheck in the browser is a little stricter than the database, never looser. - Extra spaces at the end are cut without an error: "ana" followed by 30 spaces went into
varchar(20)and came back as 20 characters. - One long value stops the whole batch. In our test, an
insert()of two rows, one with a 25-character username, failed and neither row was written.
The one-minute check
Note the number in the message and the table your request writes to. In the SQL Editor, list that table's columns that have a limit:
select column_name, data_type, character_maximum_length
from information_schema.columns
where table_schema = 'public' and table_name = 'profiles'
and character_maximum_length is not null;
If none has that number, look in every table, then check the triggers on yours:
select table_name, column_name
from information_schema.columns
where table_schema = 'public' and character_maximum_length = 50;
select tgname, tgfoid::regproc as function
from pg_trigger
where tgrelid = 'public.posts'::regclass and not tgisinternal;
Then open the failing request in your browser's Network tab, copy its body, and paste it into the console in place of {} to print each text value's length, counted the way the database counts:
const body = {};
for (const [column, value] of Object.entries(body))
if (typeof value === 'string') console.log(column, [...value].length);
The value longer than the number goes with the column you found.
Fix 1: widen the column
If the limit has no real reason, change the column to text:
alter table public.profiles alter column bio type text;
In our test, Postgres didn't rewrite the table for this, nor for a bigger varchar(100): the rows stay as they are, so it's quick even on a big table. The 324-character bio went in afterwards. Put the change in a migration, and update your ORM schema or generated types if you have them.
If it fails with "cannot alter type of a column used by a view or rule", the error's detail names the view. Drop it, change the column and create the view again, in one transaction, with the view's statement from your migrations (keep its with (security_invoker = true) and grants if it had them; select pg_get_viewdef('public.profile_previews'); shows its query):
begin;
drop view public.profile_previews;
alter table public.profiles alter column bio type text;
create view public.profile_previews as
select id, left(bio, 80) as preview from public.profiles;
commit;
"cannot alter type of a column used in a policy definition" works the same way: drop the RLS policy, change the column and create the policy again in one transaction. Both worked in our test.
If the same error still shows the old length after the change, the Data API is still using its saved copy of your tables, the schema cache. Supabase normally refreshes it by itself after a change like this. If it still fails a few seconds later, run this in the SQL Editor:
notify pgrst, 'reload schema';
In our test, before the reload, the 324-character bio still failed with "character varying(255)" although bio was already text. After it, the bio went in.
Fix 2: keep a real limit as a rule with a name
If the limit is real, such as a username of at most 20 characters, use text with a check. The error then names the rule, so your app knows which field is wrong:
alter table public.profiles
alter column username type text,
add constraint username_length check (char_length(username) <= 20);
In our test, the 24-character username then failed with "new row for relation "profiles" violates check constraint "username_length"" (23514): Supabase "new row for relation … violates check constraint" (23514).
Fix 3: give the form the same limit
Stop long values before they're sent, and catch the code so a refused save shows a clear message instead of failing quietly:
<input name="username" maxlength="20">
const { error } = await supabase.from('profiles').upsert(profile);
if (error?.code === '22001') {
// error.message has the limit, e.g. character varying(20), not the column
showError('One of the fields is too long.');
}
Don't fix it by cutting values in the database: a cast like 'the_real_alexandra_smith'::varchar(20) cuts to "the_real_alexandra_s" without an error, and the end is gone.
Fix 4: save the file path, not a signed URL
A signed URL is long and stops working when it expires, so it doesn't belong in a column anyway. Save the file's path and make the signed URL when you show the image:
// when the file is uploaded
await supabase.from('profiles').update({ avatar_url: path }).eq('id', user.id);
// when it's shown
const { data } = await supabase.storage.from('avatars').createSignedUrl(profile.avatar_url, 3600);
For a public bucket, the public URL from getPublicUrl() is shorter and fits in 255 characters (121 in our test).
Fix 5: make a column shorter only after the long rows are fixed
Find the rows that would break the new limit, fix or keep each one, then change the column:
select id, full_name, char_length(full_name)
from public.profiles
where char_length(full_name) > 10;
If an AI tool built your app
Give your AI tool this prompt, with the limit and the table from your error:
My Supabase write fails with "value too long for type character varying(255)" (22001). The message doesn't name the column. List every varchar(n) and char(n) column in my migrations, find the ones with that limit that this write touches (including tables written by triggers), and tell me which value is too long. If the limit has no reason, write a migration that changes the column to text, dropping and re-creating any view or RLS policy that uses it in the same transaction. If the limit is a real rule, change the column to text with a check (char_length(column) <= n) and give the form field the same maxlength. If the column stores a Storage signed URL, store the file path instead and create the signed URL when showing the file. Update the ORM schema or generated types too. Show me each change before making it.
Not quite your error?
- "new row for relation … violates check constraint": Supabase "new row for relation … violates check constraint" (23514).
- "null value in column … violates not-null constraint": Supabase "null value in column … violates not-null constraint" (23502).
- Sign-up fails with "Database error saving new user": Database error saving new user (Supabase).
- "invalid input syntax for type uuid": Supabase invalid input syntax for type uuid: "undefined" (22P02).
- "Could not find the '…' column of '…' in the schema cache": Supabase "Could not find the column in the schema cache" (PGRST204).
Still stuck?
Copy the request body from the Network tab and try the same insert in the SQL Editor with those values. Shorten one value at a time until the row goes in: the last one you shortened is the one that was too long.
Other Supabase problems? See Supabase fixes.