@Vanaaaaaaaaaa

Ошибка с SQL запросом?

Такая ошибка Operand should contain 1 column(s) хотя такая колонка есть возникает при обновление фото
Код

@dp.message(Edittovar.name)
async def edit_name(message: Message, state: FSMContext) -> None:
    await state.update_data(name=message.text)
    await state.set_state(Edittovar.about)
    await message.answer("Введите новое описание товара")
    date = []
    [date.append(value) for value in data.items()]
    conn = data.connect_data(host="localhost", password="Dan098070", data="data") 
    cur = conn.cursor()
    cur.execute("UPDATE aromki SET name = {} WHERE id = '{}'".format(date[0],pg))
    conn.commit()
    conn.close()
    cur.close()
@dp.message(Edittovar.about)
async def edit_about(message: Message, state: FSMContext) -> None:
    await state.update_data(about=message.text)
    await state.set_state(Edittovar.url)
    await message.answer("Введите новый юрл товара")
    date = []
    [date.append(value) for value in data.items()]
    conn = data.connect_data(host="localhost", password="Dan098070", data="data") 
    cur = conn.cursor()
    cur.execute("UPDATE aromki SET about = {} WHERE id = '{}'".format(date[1],pg))
    conn.commit()
    conn.close()
    cur.close()
@dp.message(Edittovar.url)
async def edit_url(message: Message, state: FSMContext) -> None:
    await state.update_data(url=message.text)
    await state.set_state(Edittovar.photo)
    await message.answer("Новую фотку")
    date = []
    [date.append(value) for value in data.items()]
    conn = data.connect_data(host="localhost", password="Dan098070", data="data") 
    cur = conn.cursor()
    cur.execute("UPDATE aromki SET url = {} WHERE id = '{}'".format(date[2],pg))
    conn.commit()
    conn.close()
    cur.close()
@dp.message(Edittovar.photo)
async def edit_url(message: Message, state: FSMContext) -> None:
    await state.update_data(photo=message.text)
    data = await state.get_data()
    date = []
    [date.append(value) for value in data.items()]
    conn = connect_data(host="localhost", password="Dan098070", data="data") 
    cur = conn.cursor()
    
    
    
    cur.execute(f"UPDATE aromki SET photo = {date[3]} WHERE id = '{pg}'")
    conn.commit()
    conn.close()
    cur.close()
    
    await state.clear()

  • Вопрос задан
  • 163 просмотра
Решения вопроса 1
Mike_Ro
@Mike_Ro Куратор тега Python
Python, JS, WordPress, SEO, Bots, Adversting
Operand should contain 1 column(s)

The error message “Operand should contain 1 column(s)” indicates that the query is referencing more than one column in the WHERE clause, when it should only reference one.
Ждет 1 значение, а передано несколько.
cur.execute(f"UPDATE aromki SET photo = {date[3]} WHERE id = '{pg}'")
date[3]  # ?

Что передается в date[3]?
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы