skip to Main Content

Postgresql – How can I select a Long[] field into my pojo from a lateral join using arrayAgg()?

Here is an example of the query I'm trying to execute and the POJO I'm trying to populate. public Optional<TeacherWithStudents> getTeachersWithStudentsForStudentId(long studentId) { return ctx().select( TEACHER.ID, TEACHER.NAME, DSL.field("student.ids", STUDENT_TEACHER_MAPPING.STUDENT_ID.getDataType().getArrayType())) .from(TEACHER) .leftJoin(DSL.lateral( DSL.select(DSL.arrayAgg(STUDENT_TEACHER_MAPPING.STUDENT_ID).as("ids")) .from(STUDENT_TEACHER_MAPPING) .where(STUDENT_TEACHER_MAPPING.TEACHER_ID.eq(TEACHER.ID))).as("student")) .on(DSL.condition(true)) .limit(1) .fetchOptionalInto(TeacherWithStudents.class); } // TeacherWithStudents…

VIEW QUESTION

Postgresql – Jooq converter from Postgres array to scala list

I have a scala case class case class MyRecord( id: String, dimensions: List[String], // postgres text[] dimensionCodes: List[Long] // postgres integer[] ) and a Jooq query JooqBuilder .default(conn) .select( field("id", classOf[String]), field("dimensions", classOf[List[String]]), field("dimensionCodes", classOf[List[Long]]), ) .from(table(MY_TABLE)) .fetchInto(classOf[MyRecord]) .asScala .toList…

VIEW QUESTION
Back To Top
Search