-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_generator.py
More file actions
35 lines (29 loc) · 845 Bytes
/
db_generator.py
File metadata and controls
35 lines (29 loc) · 845 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
import psycopg2
import os
with open(os.path.expanduser("~/pwds/postgrespwd.txt")) as f:
pwd = f.readline()
conn = psycopg2.connect(
f"dbname=testdb user=niels password={pwd} host=192.168.0.11")
#cur = conn.cursor()
#cur.execute("create table if not exists t2 (a integer, b integer)")
# for i in range(1000):
# for j in range(1000):
# cur.execute(r"insert into t2 (a,b) values (%(a)s, %(b)s)",
# {"a": (i+1)*(j+1), "b": j})
# cur.close()
# conn.commit()
# conn.close()
def iterdata(cursor, arraysize=1000):
while True:
res = cursor.fetchmany(arraysize)
if not res:
break
for r in res:
yield r
cur = conn.cursor()
cur.execute('select txt from public.aisdata order by sys_id')
for d in iterdata(cur):
print(d)
cur.close()
conn.commit()
conn.close()