Raizel
Joining multiple separate CTE's
I am working on a complex query. I can get it to run efficiently using multiple CTE's(Atleast in RAW SQL) but I want to port all this over to Kysely due to the typesafety.
What I want is something like this:
const cteOne = kyselyDb
.with('myCTE', (qb) =>
qb
.selectFrom('InboxFeedItem')
.limit(10)
.selectAll()
)
.as('cteOne'),
const cteTwo = kyselyDb
.with('otherCTE', (qb) =>
qb.selectFrom('InboxFeedItem').offset(10).limit(10).selectAll(),
)
.selectFrom('otherCTE')
.select('id as xId')
.as('cteTwo')
I could have a number of different CTE's (possibly returned from function calls) And I want to then JOIN them OR UNION them etc. but right now its not letting me. Maybe I don't know the syntax or is it not possible ? TYIA
14 replies