AS a beginner on Python and SQLite I am wandering if there are more elegant solutions for the tasks I have.
My current SQLite database contains several time series as:
The timestamps can simply be copied:
INSERT INTO TimeStamps(time)
SELECT time FROM Y1 UNION
SELECT time FROM Y2 UNION
SELECT time FROM Y3 UNION
SELECT time FROM Y4 UNION
SELECT time FROM Y5 UNION
SELECT time FROM Y6;
The datapoints require a lookup (using a correlated subquery) for the corresponding timestamp ID:
INSERT INTO DataPoints(timeID, VarID, value)
SELECT (SELECT timeID
FROM TimeStamps
WHERE time = all_Y.time),
VarID,
value
FROM (SELECT time, 1 AS VarID, value FROM Y1 UNION ALL
SELECT time, 2, value FROM Y2 UNION ALL
SELECT time, 3, value FROM Y3 UNION ALL
SELECT time, 4, value FROM Y4 UNION ALL
SELECT time, 5, value FROM Y5 UNION ALL
SELECT time, 6, value FROM Y6) AS all_Y;