Why not use column "fk_datasource_id" in bod.public.dataset?
You always have the bod ID which is the layer field in "sql_query".