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