-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin_04_query.py
54 lines (35 loc) · 885 Bytes
/
bin_04_query.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
44
45
46
47
48
49
50
51
52
53
54
import psycopg2;
from themuserb import cfg;
from themuserb.jobsdb import JobsDBSchema;
query \
= """
SELECT count(*)
FROM job
WHERE '2016-09-01 0:00:00' <= publication_date
AND publication_date < '2016-10-01 0:00:00'
;
""";
def main( host, user, password, dbname ):
connstr \
= "host={} ".format( host ) \
+ "user={} ".format( user ) \
+ "password={} ".format( password ) \
+ "dbname={} ".format( dbname );
conn = psycopg2.connect( connstr );
try:
print( query );
result = None;
cursor = conn.cursor();
try:
cursor.execute( query );
result = list( cursor.fetchall() )[ 0 ][ 0 ];
finally:
cursor.close();
finally:
conn.commit();
conn.close();
print( "-->", result );
print();
if __name__ == "__main__":
import sys;
main( *sys.argv );