計算機科学のブログ

ほしい物リスト

Python - SQLite - List Comprehensions: Database Integrations - distinct, timestamp

Head First Python: A Learner’s Guide to the Fundamentals of Python Programming, A Brain-Friendly GuidePaul Barry(著)、 O’Reilly Mediaの Chapter 13.(List Comprehensions: Database Integrations)、EXERCISE(589/682)の解答を求めてみる。

Jupyter(コード、入出力結果)

webapp/TryQueries.ipynb

import DBcm
from queries import SQL_SESSIONS

db_details = 'CoachDB.sqlite'
print(SQL_SESSIONS)
    select distinct ts from times
with DBcm.UseDatabase(db_details) as db:
    db.execute(SQL_SESSIONS)
    results = db.fetchall()
results
[('2025-11-29 05:20:09',)]