Note that there are some explanatory texts on larger screens.

plurals
  1. POPython sqlite3: UPDATE failure claims "no such column"
    primarykey
    data
    text
    <p>The following script evokes the following exception in the UPDATE command. What I think should happen for this simple UPDATE command is that the value of db_2.foo.bar should be doubled from 1 to 2. My guess is that I have some subtle syntax error in the UPDATE statement (or else a bug at the Python or sqlite3 level); however, I've pored over the sqlite3 documentation -- especially the "UPDATE" and "expression" pages -- and don't see that I'm doing anything wrong. </p> <pre><code>db_1.foo_bar= (1,) Traceback (most recent call last): File "try2.py", line 29, in &lt;module&gt; db_2.execute( 'UPDATE foo SET bar = bar + db_1.foo.bar WHERE rowid = db_1.foo.rowid' ) sqlite3.OperationalError: no such column: db_1.foo.bar </code></pre> <p>Any suggestions or workarounds?</p> <pre><code>import sqlite3 # Create db_1, populate it and close it: open( 'db_1.sqlite', 'w+' ) db_1 = sqlite3.connect( 'db_1.sqlite' ) db_1.execute( 'CREATE TABLE foo(bar INTEGER)' ) db_1.execute( 'INSERT INTO foo (bar) VALUES (1)' ) db_1.commit() db_1.close() # Create db_2: open( 'db_2.sqlite', 'w+' ) db_2 = sqlite3.connect( 'db_2.sqlite' ) db_2.execute( 'CREATE TABLE foo(bar INTEGER)' ) # Attach db_1 to db_2 connection: db_2.execute( 'ATTACH "db_1.sqlite" AS db_1' ) # Populate db_2 from db_1: db_2.execute( 'INSERT INTO foo SELECT ALL * FROM db_1.foo' ) # Show that db_1.foo.bar exists: cur_2 = db_2.cursor() cur_2.execute( 'SELECT bar from db_1.foo' ) for result in cur_2.fetchall(): print 'db_1.foo_bar=', result # However, the following claims that db_1.foo.bar does not exist: db_2.execute( 'UPDATE foo SET bar = bar + db_1.foo.bar WHERE rowid = db_1.foo.rowid' ) db_2.execute( 'DETACH db_1') db_2.commit() db_2.close() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload