Trying to to loop through rows from table_a, pass them into a function, and insert the outputs into table_b. I can manage to loop through rows from table_a, but as soon as i try to insert to table_b something, my script just stops.
with sqlite3.connect(db_path) as db:
cursor = db.cursor()
cursor.execute("""SELECT * FROM cars""")
for row in cursor:
car_price = get_car_price(row[0])
cursor.execute("""INSERT INTO car_prices (price, car_id) VALUES (?,?);""",(car_price, row[0]))
output :
[Finished in 1.0s]
It is weird because the below works, but as soon as i try executing to car_prices table (as in the previous code), the code just ends at first iteration.
with sqlite3.connect(db_path) as db:
cursor = db.cursor()
cursor.execute("""SELECT * FROM cars""")
for row in cursor:
print(row)
output:
(1, "car_1")
(2, "car_2")
...
(n, "car_n")
[Finished in 0.7s]
As asked, here is the .schema:
sqlite> .schema
CREATE TABLE IF NOT EXISTS "cars" (
"id" integer NOT NULL,
"name" text NOT NULL,
"website_url" text NOT NULL,
PRIMARY KEY("id")
);
CREATE TABLE IF NOT EXISTS "car_prices" (
"price_id" integer,
"price" NUMERIC NOT NULL,
"car_id" integer NOT NULL,
PRIMARY KEY("price_id"),
FOREIGN KEY("car_id") REFERENCES "cars"("id")