This error occurs when you attempt to insert or query a UUID column with a malformed value. PostgreSQL expects UUIDs in the standard 8-4-4-4-12 hexadecimal format, and will reject any value that doesn't match valid UUID syntax.
PostgreSQL uses the UUID data type to store Universally Unique Identifiers as defined by RFC 9562. When you try to insert a value into a UUID column or use it in a WHERE clause, PostgreSQL validates that the value conforms to strict formatting rules. The "Invalid input syntax for UUID" error indicates the provided value fails this validation check, typically due to malformed characters, incorrect hyphen placement, or values that aren't hexadecimal digits.
PostgreSQL accepts UUIDs in the standard format (8-4-4-4-12 hexadecimal digits):
Valid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11
Valid: A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A11 (uppercase also accepted)
Valid: a0eebc999c0b4ef8bb6d6bb9bd380a11 (no hyphens)
Invalid: a0eebc99-9c0b-4ef8-bb6d (too short)
Invalid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11-extra (extra characters)Check the value you're inserting against one of these formats.
If you're building SQL manually, ensure you're not double-quoting the UUID:
-- WRONG:
INSERT INTO users (id, name) VALUES ('"a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11"', 'John');
-- CORRECT:
INSERT INTO users (id, name) VALUES ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', 'John');If using an ORM, verify it's not wrapping the UUID in extra serialization.
If you're passing a string that might not parse automatically, use an explicit cast:
SELECT * FROM users WHERE id = 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid;
INSERT INTO users (id, name) VALUES ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid, 'John');The ::uuid cast tells PostgreSQL to validate and convert the string to UUID type.
Use a UUID validation library in your application language:
Node.js/JavaScript:
import { validate as uuidValidate } from "uuid";
const userInput = req.body.id;
if (!uuidValidate(userInput)) {
throw new Error('Invalid UUID format');
}
await prisma.user.create({ data: { id: userInput, name: 'John' } });Python:
from uuid import UUID
try:
UUID(user_input)
except ValueError:
raise Exception('Invalid UUID format')This catches format errors before they reach the database.
If using TypeORM, Sequelize, or similar ORMs, ensure UUID columns are properly typed:
TypeORM:
import { Column, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class User {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column()
name: string;
}Prisma:
model User {
id String @id @default(cuid())
name String
}Verify your ORM configuration matches your database schema.
Instead of generating UUIDs in your application, let PostgreSQL handle it:
-- For UUID v4 (random):
CREATE TABLE users (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
name text NOT NULL
);
-- Insert without specifying id:
INSERT INTO users (name) VALUES ('John');
-- For older PostgreSQL versions (< 13), use uuid-ossp extension:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE users (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
name text NOT NULL
);This eliminates manual UUID formatting errors.
PostgreSQL UUID validation is strict by design. RFC 9562 defines multiple UUID versions (v1-v7), but PostgreSQL's type system only validates the format, not the version. If you're migrating legacy data, you may need to normalize values using string functions like REGEXP_REPLACE() before casting to UUID. For distributed systems, UUIDs provide better uniqueness guarantees than serial sequences. The gen_random_uuid() function (PostgreSQL 13+) generates RFC 9562 compliant v4 UUIDs without requiring additional extensions.
ERROR: syntax error at end of input
Syntax error at end of input in PostgreSQL
Bind message supplies N parameters but prepared statement requires M
Bind message supplies N parameters but prepared statement requires M in PostgreSQL
Multidimensional arrays must have sub-arrays with matching dimensions
Multidimensional arrays must have sub-arrays with matching dimensions
ERROR: value too long for type character varying
Value too long for type character varying
insufficient columns in unique constraint for partition key
How to fix "insufficient columns in unique constraint for partition key" in PostgreSQL