-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate.py
42 lines (33 loc) · 1 KB
/
create.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
#!/usr/bin/python
import psycopg2
from datetime import date
today = str(date.today())
# print(today)
conn = psycopg2.connect(database = "testdb2", user = "postgresql", password = "namespace1", host = "sample-database.czgprnseypbr.us-east-1.rds.amazonaws.com", port = "5432")
print ('Opened database successfully')
cur = conn.cursor()
students = 5
str1 = "CREATE TABLE MAINATT (ROLL int,\""
str1 +=today
str1 += "\" int);"
cur.execute(str1)
print("Created successfully mainatt")
str1 = "CREATE TABLE second (ROLL int,Attended int,total int);"
cur.execute(str1)
print("Created successfully second")
# now inserting in table
for student in range(1,students+1):
str1 = "INSERT INTO MAINATT (ROLL,\""
str1 += today
str1 += "\") VALUES ("
str1 += str(student)
str1 += ",0);"
# print(str1)
cur.execute(str1)
str1 = "INSERT INTO SECOND (ROLL,ATTENDED,TOTAL) VALUES ("
str1+=str(student)
str1+=",0,1);"
cur.execute(str1)
print("Data inserted successfully")
conn.commit()
conn.close()