I have a column property that I would like to either return all of my ReportMetaDataEntity columns plus on more synthetic column that is an array of device_ids from a query to another table called Subject.
I have the query working when the subject_ids have integers in the array and would like that if the subject_ids array is empty to return an empty array of device_ids. To do that I was using the coalesce funtion and specifying the type of the array as a char since my device ids are strings.
Below is the column property as it stands:
ReportMetadataEntity.device_ids = column_property(
select(func.coalesce(func.array_agg(SubjectEntity.device_id), array([], type_=CHAR)))
.where(array([SubjectEntity.id]).contained_by(ReportMetadataEntity.subject_ids))
.correlate_except(SubjectEntity)
.scalar_subquery()
)
This works, but I am looking for an empty array returned not one with a single element.
ReportMetadataEntity.device_ids = column_property(
select(func.coalesce(func.array_agg(SubjectEntity.device_id), array([' '])))
.where(array([SubjectEntity.id]).contained_by(ReportMetadataEntity.subject_ids))
.correlate_except(SubjectEntity)
.scalar_subquery()
)
Any suggestions on how to approach this using column properties?
Thanks