данные в моем CSV-файле выглядят так:
081299289X,China Dolls,Lisa See,2014
0345498127,Starter for Ten,David Nicholls,2003
0061053716,Imajica,Clive Barker,1991
0553262149,Emily Climbs,L.M. Montgomery,1925
мой import.py выглядит так:
import csv
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
engine = create_engine('postgres://pnrvnavoxvnlgw:....')
db = scoped_session(sessionmaker(bind=engine))
def main():
f = open("books.csv")
reader = csv.reader(f)
for isbn, title, author, year in reader:
db.execute(
"INSERT INTO books (isbn, title, author, publication_year)
VALUES (:isbn, :title, :author, :publication_year)",
{"isbn": isbn, "title": title, "author": author, "publication_year": year}
)
db.commit()
if __name__ == "__main__":
main()
По какой-то причине я не могу понять, что не так сэтот кодэто ошибка:
sqlalchemy.exc.DataError: (psycopg2.DataError) invalid input syntax for integer: "year"
LINE 1: ...publication_year) VALUES ('isbn', 'title', 'author', 'year')
Справка?