[Python] Force Python-SQLite3 to report non-existing columns in WHERE clause

Discussão em 'Python' iniciado por Stack, Junho 23, 2025.

  1. Stack

    Stack Membro Participativo

    This is my code:

    import sqlite3

    conn = sqlite3.connect(':memory:')
    cursor = conn.cursor()

    cursor.execute('''
    CREATE TABLE schools (
    county TEXT,
    statustype TEXT
    )
    ''')

    cursor.execute('''
    INSERT INTO schools VALUES ('some_county', 'some_status')
    ''')


    cursor.execute('''
    SELECT COUNT(*) FROM schools
    WHERE county = 'Alpine'
    AND statustype IN ('Active', 'Closed')
    AND "School Type" = 'District Community Day Schools'
    ''')

    result = cursor.fetchone()[0]
    print(f"Count result: {result}")

    conn.close()


    Note that there is intentionally no 'School Type' column in the database schema in this example.

    The result is 0.

    Is possible to change some settings of SQLite3 or of the database in order to get an error about non-existing column instead?

    Continue reading...

Compartilhe esta Página