![]() |
VOOZH | about |
In this article we will look into the process of inserting data into a PostgreSQL Table using Python. To do so follow the below steps:
conn = psycopg2.connect(dsn)
cur = conn.cursor()
cur.execute(sql, (value1,value2))
conn.commit()
cur.close() conn.close()
Example:
For example we will use the Student table of the school database that we created in the earlier sections of the article series.
Here we will create a insert_student() function to insert student_name row to the student table:
Now to verify the insertion use the following command in the psql shell:
SELECT * FROM student;
Output:
👁 Image