I am trying to make the following SQL alchemy orm query work :
query = (
sqlalchemy.select(
cls.tasks_table.id.label("task_id"),
cls.tasks_table.doc.label("task_doc"),
cls.table.id.label("job_id"),
cls.table.doc.label("job_doc"),
)
.select_from(
func.jsonb_to_record(cls.tasks_table.doc).alias("x(job_id uuid)"),
)
.join_from(cls.table, func.jsonb_to_record(cls.tasks_table.doc), 'job_id' == cls.table.id)
)
yet this generates the following SQL query :
SELECT public.tasks.id AS task_id, public.tasks.doc AS task_doc, public.jobs.id AS job_id, public.jobs.doc AS job_doc
FROM jsonb_to_record(public.tasks.doc) AS "x(job_id uuid)", public.jobs
JOIN public.jobs ON public.jobs.id = :id_1
The problem here are the apostrophes around x(job_id uuid)
. without it, the SQL query will be correct.
Any idea how to pass the x(job_id uuid)
part while using jsonb_to_record
?
My goal is to use this column for joining another table layer in the join_from
clause.