The SQLite now argument is stable within the same query

I stumbled across an interesting little detail of SQLite today, running the following query:

select strftime('%s','now') || substr(strftime('%f','now'),4) as t1
union all
select strftime('%s','now') || substr(strftime('%f','now'),4)
union all
select strftime('%s','now') || substr(strftime('%f','now'),4)
union all
select strftime('%s','now') || substr(strftime('%f','now'),4)
union all
select strftime('%s','now') || substr(strftime('%f','now'),4)
union all
select strftime('%s','now') || substr(strftime('%f','now'),4)

That strftime() pattern is described here and in this TIL, it returns the current Unix timestamp in milliseconds.

The result of the above query is:

t1
1675631847614
1675631847614
1675631847614
1675631847614
1675631847614
1675631847614

I was expecting each timestamp to differ by a few milliseconds, but they're all the same.

I spotted why in the SQLite Date and Time Functions documentation:

The 'now' argument to date and time functions always returns exactly the same value for multiple invocations within the same sqlite3_step() call.

Created 2023-02-05T13:23:12-08:00 · Edit