-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
36 lines (28 loc) · 722 Bytes
/
Copy pathscript.py
File metadata and controls
36 lines (28 loc) · 722 Bytes
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
35
36
"""This script connects to a PostgreSQL database list all tables."""
import datetime
import os
import psycopg2
def fun():
"""This function prints the current date and time."""
now = datetime.datetime.now()
print(now)
if __name__ == "__main__":
conn = psycopg2.connect(
dbname="postgres",
user="postgres",
password=os.environ["POSTGRES_PASSWORD"],
port=5432,
host="docker-postgres",
)
conn.autocommit = True
cursor = conn.cursor()
sql = """
select * from information_schema.tables
"""
cursor.execute(sql)
results = cursor.fetchall()
print(results)
counter = 0
while counter < 10:
fun()
counter += 1