It's a simple query to fetch attendance rows for a student on a particular date.
Conditions 1. If a student has attendance for that date get it 2. If not just retrieve student columns
My query looks like
Select 0 as attendanceId, 0 as attendanceVersion, '' as inTime,'' as
outTime,'' as summary,Student.id As
StudentId,Student.firstName,Student.lastName
From Student where student.id not in
( Select student.id From Student join Attendance on ( student.id =
Attendance.studentId )
where attendance.inactiveDate is null and student.inactivedate is
null and
date(attendance.intime) = '2019-06-23' )
and student.inactivedate is null
UNION
Select Attendance.id As AttendanceId,Attendance.version,Attendance.inTime,Attendance.outTime,Attendance.summary,
Student.id As StudentId,Student.firstName,Student.lastName
From Student join Attendance on ( student.id = Attendance.studentId ) where
attendance.inactiveDate is null and student.inactivedate is null and
date(attendance.intime) = '2019-06-23'
order by student.firstname, student.id
What I'm trying to do: Select student rows without attendance and union join it with student rows with attendance.
Problem: Getting the following error
ERROR: invalid input syntax for type timestamp with time zone: ""
SQL state: 22007
Character: 51
I was hoping postgres would gracefully substitute empty literal for timezone. How to substitute empty string for timezone or a better way to do this query
UPDATE:
Select
Attendance.id As AttendanceId,Attendance.version, Attendance.inTime,Attendance.outTime,Attendance.summary,
Student.id As StudentId,Student.firstName,Student.lastName
From Student left join Attendance on ( student.id = Attendance.studentId )
where student.inactivedate is null and date(attendance.intime) = '2019-06-23'
order by student.firstname, student.id
Produces a single row like a inner join. Guess it's because I'm joining on Studentid on attendance?!

''isn't a valid constant for a timestamp value. You need to usenull::timestamptz as intimeinstead of'' as intimein your first query to select an "empty" timestamp value.