I'm trying to run a program to insert data from a CSV. file into a PostgreSQL database.
db.execute("INSERT INTO books (isbn, title, author, year) VALUES (:isbn, :title, :author, :year)",
{"isbn": isbn, "title": title, "author": author, "year": year})
The code crashed and returned this:
sqlalchemy.exc.DataError: (psycopg2.errors.InvalidTextRepresentation)
invalid input syntax for type integer: "isbn" LINE 1: ...RT INTO
books (isbn, title, author, year) VALUES ('isbn', 't...
^
[SQL: INSERT INTO books (isbn, title, author, year) VALUES (%(isbn)s,
%(title)s, %(author)s, %(year)s)] [parameters: {'isbn': 'isbn',
'title': 'title', 'author': 'author', 'year': 'year'}] (Background on
this error at: http://sqlalche.me/e/9h9h)
I took the syntax from the import.py source code and modified the values.
The format of my books table is:
- id SERIAL PRIMARY KEY
- isbn INTEGER PRIMARY KEY
- title VARCHAR NOT NULL
- author VARCHAR NOT NULL
- year INTEGER NOT NULL
Can anyone tell me what is wrong with my syntax?