Python Forum
UPDATE SQLITE TABLE - Copy a fields content to another field.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UPDATE SQLITE TABLE - Copy a fields content to another field.
#1
Hi, I am trying to go through filtered records and copy the contents, line by line, of field1 to field2.

Why is the field2 being filled with the same value and not it's corresponding field1 value?

Thanks.

import sqlite3
conn = sqlite3.connect("test.sqb")
cursor = conn.cursor()

sql = "SELECT * FROM report WHERE type LIKE 'E%'"

cursor.execute(sql)
data = cursor.fetchall()

for row in data:
    field1 = row[0]
    cursor.execute("UPDATE report SET field2='" + field1 + "'")
    conn.commit()
conn.close()
Reply


Messages In This Thread
UPDATE SQLITE TABLE - Copy a fields content to another field. - by andrewarles - May-07-2021, 04:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy xml content from webpage and save to locally without special characters Nik1811 14 608 Mar-26-2024, 09:28 AM
Last Post: Nik1811
Thumbs Up Convert word into pdf and copy table to outlook body in a prescribed format email2kmahe 1 705 Sep-22-2023, 02:33 PM
Last Post: carecavoador
Question Using SQLAlchemy, prevent SQLite3 table update by multiple program instances Calab 3 704 Aug-09-2023, 05:51 PM
Last Post: Calab
  Compare fields from two csv files georgebijum 3 1,335 Apr-25-2022, 11:16 PM
Last Post: Pedroski55
  Display table field on multiple lines, 'wordwrap' 3python 0 1,747 Aug-06-2021, 08:17 PM
Last Post: 3python
  How to update values in a pyarrow table? xraphael75 1 3,626 Jan-25-2021, 02:14 PM
Last Post: xraphael75
Question Python + Google Sheet | Best way to update specific cells in a single Update()? Vokofe 1 2,627 Dec-16-2020, 05:26 AM
Last Post: Vokofe
  Bug ? when dataclass field name == field type Cyril 0 1,526 Oct-22-2020, 03:26 AM
Last Post: Cyril
  Unable to Update SQLite Table sambanerjee 5 2,867 Sep-30-2020, 12:21 PM
Last Post: Larz60+
  Json fields not being retrieved mrcurious2020 4 1,989 Sep-14-2020, 06:24 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020