Skip to content

examples#

Querying columns with native SQL types

The field values of experiments stored in SQL tables can be queried directly with SQL if they are among the ones that provide a native SQL type. These include bool, int, float, string, time, datetime, date, UUID, and bytes.

Why should you care?

You can quickly build a reporting dashboard using your existing infrastructure (database and dashboard) at no added complexity/cost.

Querying columns with native SQL types

import datetime

from mltraq import create_session
from mltraq.steps.init_fields import init_fields

session = create_session()
experiment = session.create_experiment("example")
now = datetime.datetime.strptime(
    "05/03/2024 10:55:12", "%d/%m/%Y %H:%M:%S"
)
experiment.execute(init_fields(now=now, one=1, two=2)).persist()

print(session.db.query("SELECT now, one + two FROM experiment_example"))
Output
                          now  one + two
0  2024-03-05 10:55:12.000000          3