PostgreSQL error: syntax error at or near "user"
Quick answer
"user" (along with "order", "group", "table", and others) is a reserved SQL keyword in PostgreSQL. Using it unquoted as a table or column name causes a syntax error. Either quote it with double quotes everywhere, or — better — rename it to avoid the conflict entirely.
What causes this error
PostgreSQL reserves certain words for its own SQL grammar. user, order, group, and table are common ones that trip people up because they're also completely natural names for application data.
The Fix
-- Quoting works but has to be done everywhere, forever, including in every ORM query
SELECT * FROM "user";
-- Better: rename the table to sidestep the conflict entirely
ALTER TABLE "user" RENAME TO users;If you're using Prisma, this is exactly what @@map("users") on a model named User is for — keep the clean singular name in your schema, but map it to a safe plural table name in the actual database.
model User {
id String @id @default(cuid())
// ...
@@map("users")
}Common causes / variations
- Naming a model directly after a common noun that happens to be reserved (
user,order,group) - Writing raw SQL migrations by hand without quoting a reserved identifier
- Copying a schema from a different database engine with different reserved word rules
Related errors
See also: relation does not exist, current transaction is aborted.
Was this fix helpful?
Comments
Loading comments...