Postgresql Join select columns with case
const res = await db.select({
...getTableColumns(table1),
items: table2
}).from(table1).leftJoin(table2, eq(table1.id, table2.mainId))const res = await db.select({
...getTableColumns(table1),
items: table2
}).from(table1).leftJoin(table2, eq(table1.id, table2.mainId))in this case i want to get table2 tables with
db.select({
...getTableColumns(table2),
partNumber: sql<string>`case when ${products.id} is not null then ${products.partNumber} else ${inventoryItems.partNumber} end`,
name: sql<string>`case when ${products.id} is not null then ${products.nameEn} else ${inventoryItems.name} end`,
}).from(table2)db.select({
...getTableColumns(table2),
partNumber: sql<string>`case when ${products.id} is not null then ${products.partNumber} else ${inventoryItems.partNumber} end`,
name: sql<string>`case when ${products.id} is not null then ${products.nameEn} else ${inventoryItems.name} end`,
}).from(table2)like this how to do this?