Composite key with different sorting order

pgTable(
'admin_patient_message',
{
id: char('id', { length: 36 }).primaryKey().notNull(),
message: text('message').notNull(),
patientId: char('patient_id', { length: 36 }).notNull(),
senderId: char('sender_id', { length: 36 }).notNull(),
attachments: json('attachments'),
sentAt: bigint('sent_at', { mode: 'number' }).notNull(),
},
(t) => ({
// Index modified on the generated schema
patientMessagesIdx: index('patient_messages_idx').on(t.patientId, t.sentAt),
})
);
pgTable(
'admin_patient_message',
{
id: char('id', { length: 36 }).primaryKey().notNull(),
message: text('message').notNull(),
patientId: char('patient_id', { length: 36 }).notNull(),
senderId: char('sender_id', { length: 36 }).notNull(),
attachments: json('attachments'),
sentAt: bigint('sent_at', { mode: 'number' }).notNull(),
},
(t) => ({
// Index modified on the generated schema
patientMessagesIdx: index('patient_messages_idx').on(t.patientId, t.sentAt),
})
);
I wanted to make a composite index on the patientId and sentAt but I wanted the sentAt to be in DESC order. This is what the index I wanted to have CREATE INDEX IF NOT EXISTS "patient_messages_idx" ON "admin_patient_message" ("patient_id","sent_at" DESC);
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server