skip to Main Content

Inserting data with parameters to PostgreSQL 16

I'm trying to insert data with parameters to PostgreSQL 16 in C#. I have the following code: using (var myConnection = new NpgsqlConnection(myConnectionString)) { myConnection.Open(); var insertAllData = $@" DO $$ DECLARE new_production_item_id INTEGER; BEGIN INSERT INTO public.production_items (my_data_type_id, created_by,…

VIEW QUESTION

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
Back To Top
Search