T
T
TanderOFF2021-07-28 16:29:52
Python
TanderOFF, 2021-07-28 16:29:52

How to change value in SQLite json?

Good afternoon !
The question is.. How to change values ​​in sqlite if there is json ? I wanted to change the value of the id line to another

with sqlite3.connect('base.db') as conn:
    cursor = conn.cursor()
    cursor.execute(f"SELECT nabor FROM inv where ids={ctx.author.id}")
    data = cursor.fetchall()
    print(data)
data['id'] = '99'
 #Как записать в data значение 99 обратно в базу ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-07-28
@rozhnev

with sqlite3.connect('base.db') as conn:
    cursor = conn.cursor()
    cursor.execute(f"UPDATE inv SET nabor = json_replace(nabor, '$.id', 99) WHERE ids={ctx.author.id}")
    con.commit()

https://www.sqlite.org/json1.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question