0

So this is part of the import.py code in project1:

    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?

0

Have a look at the ISBN column in the spreadsheet to determine why postgreSQL thinks it cannot store the data in an int column.

NB some (many?) isbns start with the numeral 0, and it is a significant digit, which cannot be stored in an int column.

1
  • ISBN was an string and therefore could not be stored as an int. thanks DINO
    – Chris
    May 21 '20 at 20:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .