PostgreSQL: invalid input syntax for type uuid
ERROR: invalid input syntax for type uuid: "<value>"A value sent to a uuid column is not a valid UUID, often an empty string, a truncated value, or an integer id. Validate and format UUIDs before insert, and convert empty strings to NULL.
What this error means
Postgres uuid columns accept only well-formed UUIDs, 32 hex digits in the standard grouping. Anything else, including an empty string or a numeric id, fails this conversion, and the message quotes the offending value.
It commonly comes from a form field or API that sends an empty string or a wrong id type.
How to fix it
An empty string reaches the uuid column
Convert an empty string to NULL before insert.
INSERT INTO t (id) VALUES (NULLIF($1, '')::uuid);The value is malformed
Validate the UUID format in the application before sending it.
You need to generate one
Use gen_random_uuid() on Postgres 13+, or uuid_generate_v4() from uuid-ossp on older versions.
INSERT INTO t (id) VALUES (gen_random_uuid());How to avoid it next time
- Validate UUIDs at the application boundary.
- Map empty form fields to null before they reach the database.
Frequently asked questions
Why does an empty string fail?
An empty string is not a UUID, and Postgres will not coerce it to NULL automatically. Use NULLIF(value, '') to convert it.
How do I generate a UUID in Postgres?
gen_random_uuid() is built in on Postgres 13 and later. Before that, use uuid_generate_v4() from the uuid-ossp extension.
Stop struggling with SQL
Use FluentDB, the AI database client for macOS.
Related errors
Part of the PostgreSQL error reference. Last reviewed 2026-07-31.