Follow

I found a way to sort of set dynamic default values in SQLite. It's somewhat obvious, but basically:

Set the default to, e.g. 'static_default', then CREATE TRIGGER name AFTER INSERT ON table WHEN new.field = 'static_default' BEGIN UPDATE table SET field=generate_dynamic_value() WHERE ROWID = new.ROWID; END;

In my case I'm using this to have INTEGER hour and minute fields that default to the current time, so 'current_minute' (SQLite is weakly typed) gets replaced with strftime('%M', 'now').

· · brutaldon · 0 · 1 · 0
Sign in to participate in the conversation
Fosstodon

Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.