Posts

Showing posts from June, 2019

PostgreSQL With Python

Image
  Setup For Work step 1: Install pgadmin4 in your system (Note* please remember root password)   step 2: create a database in the name 'test-all' step 3: create a virtual environment (if you don't know then  visit here ) step 4: pip install psycopg2 step 5: Now create a python script and try with the below code Code Connecting Database: import psycopg2 def connect_my_db (db, user, password, host):     try:         connection = psycopg2.connect(         database=db, user = user,          password = password, host = host,          port = "5432")         print("Database Connected")                    return  connection     except Exception as e:         print("Unable to connect DB") connection   =  connect_my_db ('test-all', 'postgres', '12345', '127.0.0.1') Create Table : import psycopg2 import db_connect connection = db_connect.connect_my_db('test-all', 'postgres', '12345', '127.0.0.1&#