Answer the question
In order to leave comments, you need to log in
An error occurred while creating the table, how to solve it?
Hello everyone, I want to create a table in postgresql using python, but an error occurs( cur.execute("""CREATE TABLE {}
psycopg2.errors.SyntaxError: ERROR: syntax error (approximate position: "688093622")), here is the code:
if user_id_v not in mas_user_id:
mas_user_id.append(user_id_v)
print('Новый пользователь БОТА: ', mas_user_id[-1])
conn = psycopg2.connect(
host='localhost',
database='',
user='',
password='',
port=5432
)
cur = conn.cursor()
# Создание таблицы
# Создание таблицы
cur.execute(f'''CREATE TABLE {user_id}
(ADMISSION INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
COURSE CHAR(50),
DEPARTMENT CHAR(50));''')
print("Table created successfully")
conn.commit()
conn.close()
conn.commit()
conn.close()
Answer the question
In order to leave comments, you need to log in
cur.execute(f'''CREATE TABLE "{user_id}"
(ADMISSION INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
COURSE CHAR(50),
DEPARTMENT CHAR(50));''')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question