Skip to content

sqlite3 docs: explain SELECT-with-literals trick #96165

Closed
@erlend-aasland

Description

@erlend-aasland

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirtopic-sqlite3type-featureA feature request or enhancement

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions