Appending to a SQLite history table
Each week, the team writes the latest digital format summary back to a shared SQLite history table. The table already holds last week's snapshot, and you want this week's results added on top, not replacing what's there. Use the write_database method with the right if_table_exists value.
This week's summary is in weekly_summary, and the SQLite URI is in uri. The existing table is printed for you, so you can compare it with what you write.
Este exercicio faz parte do curso
Scaling and Optimizing Data Pipelines with Polars
Instruções do exercicio
- Call the method that writes a DataFrame back to a SQL table.
- Add the argument that controls how an existing table is handled.
- Set its value so the new rows are appended.
exercicio interativo prático
Tente este exercicio completando este código de exemplo.
# Append this week's summary to the history table
weekly_summary.____(
table_name="weekly_format_history",
connection=uri,
# Append instead of replace or fail
____="____",
)
print("\nHistory after the write:")
print(
pl.read_database_uri(
"SELECT * FROM weekly_format_history",
uri=uri,
engine="adbc",
)
)