This commit is contained in:
Minh VU
2024-12-11 13:08:46 +01:00
parent 6b20a03bb2
commit 676057fde8
2 changed files with 9 additions and 27 deletions

View File

@@ -66,14 +66,16 @@ def create_tables_postgres():
try:
with connect_postgres() as conn:
with conn.cursor() as cursor:
start_time = time.time()
for command in sql_command_create_table:
cursor.execute(command)
conn.commit()
end_time = time.time()
cursor.close()
conn.close()
except (psycopg2.DatabaseError, Exception) as error:
print(error)
return end_time-start_time
def create_data_postgres():
sql_command_copy =(
@@ -83,14 +85,16 @@ def create_data_postgres():
try:
with connect_postgres() as conn:
with conn.cursor() as cursor:
start_time = time.time()
for command in sql_command_copy:
cursor.execute(command)
conn.commit()
end_time = time.time()
cursor.close()
conn.close()
except (psycopg2.DatabaseError, Exception) as error:
print(error)
return end_time - start_time
def requete_postgres(str):
try:
@@ -99,12 +103,12 @@ def requete_postgres(str):
start = time.time()
cursor.execute(str)
conn.commit()
temps = time.time() -start
print("Cette requête prends:", temps, "seconde")
end = time.time() -start
cursor.close()
conn.close()
except (psycopg2.DatabaseError, Exception) as error:
print(error)
return end-start
def reset_database_postgres():
try: