Search
 
SCRIPT & CODE EXAMPLE
 

SQL

python postgresQL select table

import psycopg2

try:
    connection = psycopg2.connect(user="sysadmin",
                                  password="pynative@#29",
                                  host="127.0.0.1",
                                  port="5432",
                                  database="postgres_db")
    cursor = connection.cursor()
    postgreSQL_select_Query = "select * from mobile"

    cursor.execute(postgreSQL_select_Query)
    print("Selecting rows from mobile table using cursor.fetchall")
    mobile_records = cursor.fetchall()

    print("Print each row and it's columns values")
    for row in mobile_records:
        print("Id = ", row[0], )
        print("Model = ", row[1])
        print("Price  = ", row[2], "
")

except (Exception, psycopg2.Error) as error:
    print("Error while fetching data from PostgreSQL", error)

finally:
    # closing database connection.
    if connection:
        cursor.close()
        connection.close()
        print("PostgreSQL connection is closed")
Comment

PREVIOUS NEXT
Code Example
Sql :: xampp import sql file command line 
Sql :: t-sql drop function if exists 
Sql :: sql server change schema of a table 
Sql :: how to copy data in sql 
Sql :: oracle running queries sql 
Sql :: update with select postgresql 
Sql :: mysql connection w3 
Sql :: eliminate zero from integer mysql 
Sql :: oracle list grants on package 
Sql :: postgres set null 
Sql :: postgresql combine values in one field 
Sql :: oracle percentage 
Sql :: oracle sql drop column if exists 
Sql :: how to delete the rows with null values in mysql 
Sql :: mysql récupérer le code création de vue 
Sql :: SQL Multiple Cases 
Sql :: return result of function in postgresql 
Sql :: check database size in gb mysql 
Sql :: postgresql stored procedure update table values 
Sql :: else if mysql 
Sql :: PostgreSQL types and C# types 
Sql :: mysql compare timestamp in minutes 
Sql :: create date sql 
Sql :: mysql count by month 
Sql :: Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to OFF 
Sql :: WHERE not regex in SQL 
Sql :: oracle dependency 
Sql :: postgres integer to serial 
Sql :: mysql import database 
Sql :: PL SQL VARRAY of records 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =