I actually found a way of doing it.
I used pgr_dijkstraCost() which now has a Many-to-Many implementation and exactly does what I want.
My query is :
SELECT start_vid as building, end_vid as plant, agg_cost as junction_length from pgr_dijkstraCost
(
'SELECT gid as id, i as source , j as target , length as cost from network_edges'
, array(SELECT id from "network_nodes" where buildingID!='NULL' IS NOT NULL)
, array(SELECT id from "network_nodes" where plant_name!='NULL' IS NOT NULL)
, false
)
Where network_nodes comes from a SHP MultiPoints file with every points of the network. It has attributes such as id, buildingID, plant name. Some points, which represent buildings have not NULL buildingID, some others, the plants have not NULL plant_name. Finally, some points does not have anything else than an ID and they represent vertices of the network.
The network_edges comes SHP PolyLine file and represent the network itself. It has i, j and length attributes. i and j represent, respectively, source and targed vertices of the edge and length is obviously the length of it.
I used the Networks plugin to create my graph (nodes and edges) and shp2pgsql to import it in my database.