Database tables creation
unknown
python
2 years ago
1.1 kB
8
Indexable
import psycopg2
def connect_db():
try:
con = psycopg2.connect(database="db", user="postgres", password="postgres", host="10.227.211.142", port="5432")
return con
except Exception as error:
print("An error occurred trying to connect to the database: " + error)
def create_tables(con):
if(con is None):
return
cursor = con.cursor()
# Change table's name.
cursor.execute('CREATE TABLE IF NOT EXISTS "WELD_SAMPLES_[groupid]" (\
"id" serial, \
"time_start" float, \
"time_end" float, \
"environment_t" float, \
"motor_bearing_t" float, \
"spindle_bearing_t" float, \
"counter" int, \
"sdintensity" float, \
"times" float ARRAY, \
"angular_velocity" float ARRAY, \
"force" float ARRAY, \
"displacement" float ARRAY\
)')
# Missing algorithm results table creation...
con.commit()
cursor.close()
con.close()
def run():
con = connect_db()
create_tables(con)
if __name__ == '__main__':
run()Editor is loading...