© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•2y ago
tzezar

coalesce

I wonder how to make COALESCE(smth, 0) with drizzle? Postgresql

            const sq = tx.select({
                paymentId: settlementTransaction.paymentId,
                alreadyReleased: sum(settlementTransaction.amount).as('alreadyReleased')
            })
                .from(settlementTransaction)
                .groupBy(settlementTransaction.paymentId)
                .as('sq');
                

            let r = await tx
                .select()
                .from(payment)
                .leftJoin(sq, eq(sq.paymentId, payment.id))
                .where(and(eq(payment.fromCustomerId, s.fromCustomerId), eq(payment.type, 'PREPAID')))
            const sq = tx.select({
                paymentId: settlementTransaction.paymentId,
                alreadyReleased: sum(settlementTransaction.amount).as('alreadyReleased')
            })
                .from(settlementTransaction)
                .groupBy(settlementTransaction.paymentId)
                .as('sq');
                

            let r = await tx
                .select()
                .from(payment)
                .leftJoin(sq, eq(sq.paymentId, payment.id))
                .where(and(eq(payment.fromCustomerId, s.fromCustomerId), eq(payment.type, 'PREPAID')))


I need COALESCE(alreadyReleased, 0)
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

utility function for COALESCE
Drizzle TeamDTDrizzle Team / help
14mo ago
Use COALESCE in index
Drizzle TeamDTDrizzle Team / help
2y ago
Optional filter param, coalesce to true?
Drizzle TeamDTDrizzle Team / help
3y ago
COALESCE to json array not working in sql function
Drizzle TeamDTDrizzle Team / help
13mo ago