Multiple timeseries, pivot column

I’d like to know if it’s possible and how to render multiple timeseries defining one column of the result set as a pivot column. For some queries I don’t know in advance how many series I’m getting hence is not possible to create a multi column query. At the moment I’m using tablefunc in postgresql but it’s very annoying solution indeed we need to know the columns name in advance

Result set is in this form:

t, series_name, value
0.0, s1, 12
0.0, s2, 13
1.0, s1, 14
1.0, s2, 12

it would be very good if we could define the column series_name as the pivot column and have grafana automatically plots two series, one per s1 lines and one per s2 lines