- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to insert a Python tuple in a PostgreSql database?
PostgreSql database is by default installed on port number 5432. Python interface to PostgreSql is provided by installing psycopg2 module. Assuming that test database and employee table with fname, sname, age, gender and salary fields is available.
First establish connection and obtain cursor object by following statements in Python script.
import psycopg2 conn = psycopg2.connect(database = "test", user = "postgres", password = "pass123", host = "localhost", port = "5432") cur = conn.cursor()
Data to be inserted in employee table is stored in the form of tuple object
t1=('Mac', 'Mohan', 20, 'M', 2000)
Next set up the insert query using this tuple
sql="insert into employee values(%s,%s,%d,%s,%d)" %t1
Now this query is executed using the cursor object
Result of this statement will be that employee table will show new record added in it.
- How to insert a Python tuple in a MySQL database?
- How to connect to PostgreSQL database using a JDBC program?
- Database INSERT Operation in Python
- How to create a table in PostgreSQL?
- How to insert values from one table into another in PostgreSQL?
- How to insert data into a MySQL database with Java?
- How to insert a record into a table in a database using JDBC API?
- How to insert Timestamp value in a database using JDBC program?
- How to insert/store JSON array into a database using JDBC?
- How to insert new documents into a MongoDB collection in your database?
- How to insert current date and time in a database using JDBC?
- How to Query a DB in pgAdmin in PostgreSQL?
- How to iterate through a tuple in Python?
- How to insert DECIMAL into MySQL database?
- How to convert a list into a tuple in Python?