redchicken
redchicken

Reputation: 319

Insert error while inserting data to PostgreSQL with python psycopg2

 try:
            for i in (0, nCount):
                query = "INSERT INTO students (Name, ID, Birth) VALUES (%s %d %d);"
                data = ('Y', 2, 9)
                cur.execute(query, data)
                conn.commit()

 except:
            print("I can't INSERT into students")

Connect to database and select operation are work but insert operation is not.
I use PostgreSQL and pgAdmin4
And create database use pgAdmin4
The DB structure is Name(text), Id(integer), Birth(integer)

-------------------------------------------------------------------------
Solve
* Change type of all columns to text (not text[]).
* Change column name in DB to small letter.

Upvotes: 0

Views: 584

Answers (1)

Vasyl Moskalov
Vasyl Moskalov

Reputation: 4650

From my best knowledge you missed , in values clause. I think you need write smthng like values (%s,%d,%d)

Upvotes: 1

Related Questions