-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgresql_functions.py
43 lines (35 loc) · 1.01 KB
/
postgresql_functions.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
35
36
37
38
39
40
41
42
43
### Defines a generic SQL query function to execute SELECT queries
def sql_explore(q, cnn):
"""
q : the SQL query as text
cnn : the connection parameter
"""
errors_list = []
elem = []
with cnn.cursor() as curs:
try:
### Décommenter pour nouvelle exécution
curs.execute(q)
elem = curs.fetchall()
cnn.commit()
except Exception as e:
cnn.rollback()
print(e)
errors_list.append(e)
return [elem, errors_list]
### Defines a generic SQL query function to execute DDL queries
def sql_execute(q, cnn):
"""
q : the SQL query as text
cnn : the connection parameter
errors_list = []
with cnn.cursor() as curs:
try:
### Décommenter pour nouvelle exécution
curs.execute(q)
cnn.commit()
except Exception as e:
cnn.rollback()
errors_list.append(e)
return [errors_list]
"""