Closed
Description
Some examples use the following SQL trick:
# setup code; we only need a "dummy" connection
import sqlite3
cx = sqlite3.connect(":memory:")
# returns one row with one column: ("a",)
row = cx.execute("select 'a' as literal").fetchone()
# do stuff with result
print(row)
Some people may find such examples strange, because:
- we create a connection to an empty database; it is not immediately obvious why we do this
- it may not be immediatly obvious that you can construct a resulting row by using literals in your query
We may consider one or more of the following:
- Add a very short SQL tutorial
- Add an SQL (and/or) SQLite tips and tricks howto
- Explain how SQL queries work (what is a resulting row , etc.)
Originally posted by @erlend-aasland in #96122 (comment)
Linked PRs
- gh-96165: Clarify passing ":memory:" in sqlite3.connect(). #106451
- gh-96165: Clarify omitting the FROM clause in SQLite queries. #106513
- [3.12] gh-96165: Clarify omitting the FROM clause in SQLite queries (GH-106513) #106645
- [3.11] gh-96165: Clarify omitting the FROM clause in SQLite queries (GH-106513) #106646
- [3.12] gh-96165: Clarify passing ":memory:" in sqlite3.connect() (GH-106451) #106647
- [3.11] gh-96165: Clarify passing ":memory:" in sqlite3.connect() (GH-106451) #106648
Metadata
Metadata
Assignees
Projects
Status
Done