· 4 years ago · Jul 07, 2021, 01:52 PM
1from psycopg2 import connect
2
3def createTable(tablename, column):
4 db = connect("host='localhost' dbname='artimemory' user='arti' password='password'")
5 cur = db.cursor()
6 for x in column:
7 x = '''CREATE TABLE IF NOT EXISTS tablename (column)'''
8 cur.execute(x)
9 print('Column created')
10
11column = 'ID serial primary key, Username text not null, Name text null, Join timestamp not null, friends date null'
12columnnames = column.split(',')
13tablename = 'Main'
14createTable(tablename, columnnames)
15print('Tables with columns and pseudotypes are created')
16
17
18
19
20/usr/bin/python3.9 /home/user/ReDe/lifetest.py
21Traceback (most recent call last):
22 File "/home/user/ReDe/lifetest.py", line 45, in <module>
23 createTable('Main', columnnames)
24 File "/home/user/ReDe/lifetest.py", line 40, in createTable
25 cur.execute(x)
26psycopg2.errors.SyntaxError: syntax error at or near "column"
27LINE 1: CREATE TABLE IF NOT EXISTS tablename (column)
28 ^
29
30
31Process finished with exit code 1
32
33