Drizzle generates PG statement with parentheses on order by clause

Hello! I'm trying to execute a simple query with Drizzle, but it generates an invalid SQL statement.
import { desc, eq } from 'drizzle-orm';
await db
.select()
.from(messages)
.where(eq(messages.conversationId, id))
.orderBy([desc(messages.id)])
.limit(10)
import { desc, eq } from 'drizzle-orm';
await db
.select()
.from(messages)
.where(eq(messages.conversationId, id))
.orderBy([desc(messages.id)])
.limit(10)
This is the generated SQL:
select "id", "conversation_id", "content", "created_at", "updated_at"
from "messages"
where "messages"."conversation_id" = $1
order by ("messages"."id" desc)
limit $2
select "id", "conversation_id", "content", "created_at", "updated_at"
from "messages"
where "messages"."conversation_id" = $1
order by ("messages"."id" desc)
limit $2
(error: syntax error at or near "desc" at character 113) Looks like a parentheses is added on the order by clause. Am I doing something wrong?
4 Replies
Thiago Felisberto
Thiago FelisbertoOP14mo ago
As a side note, the following works:
tx.query.messages.findMany({
where: eq(messages.conversationId, conversationId),
orderBy: [desc(messages.id)],
})
tx.query.messages.findMany({
where: eq(messages.conversationId, conversationId),
orderBy: [desc(messages.id)],
})
Angelelz
Angelelz14mo ago
await db
.select()
.from(messages)
.where(eq(messages.conversationId, id))
.orderBy(desc(messages.id))
.limit(10)
.orderBy()
await db
.select()
.from(messages)
.where(eq(messages.conversationId, id))
.orderBy(desc(messages.id))
.limit(10)
.orderBy()
Have you tried not passing an array?
Thiago Felisberto
Thiago FelisbertoOP14mo ago
Yes. Same error.
Angelelz
Angelelz14mo ago
That shouldn't happen, can you put together a minimal repro?
Want results from more Discord servers?
Add your server