-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgretest.py
35 lines (28 loc) · 972 Bytes
/
postgretest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from psycopg2 import connect
import psycopg2
import click
import flask
# Connect to an existing database
connection = psycopg2.connect(user="postgres",
password="pynative@#29",
host="127.0.0.1",
port="80",
database="postgres_db")
# Create a cursor to perform database operations
cursor = connection.cursor()
# Print PostgreSQL details
print("PostgreSQL server information")
print(connection.get_dsn_parameters(), "\n")
# Executing a SQL query
cursor.execute("SELECT version();")
# Fetch result
record = cursor.fetchone()
print("You are connected to - ", record, "\n")
if (connection):
cursor.close()
connection.close()
print("PostgreSQL connection is closed")
#conn = psycopg2.connect("dbname=test user=postgres")
#cur = conn.cursor()
#cur.execute("SELECT * FROM my_data")
#records = cur.fetchall()