D
D
DTPlayer2020-11-23 16:36:48
Python
DTPlayer, 2020-11-23 16:36:48

How to solve output problem in sqlite3?

The code:

import sqlite3
import datetime

with sqlite3.connect('test_db', detect_types = sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) as con:
    cur = con.cursor()
    try:
        data = cur.execute('SELECT * FROM vip_users').fetchall()
        print(data)
    except sqlite3.OperationalError:
        print('ERROR')

Mistake:

File "/home/lastwek/Desktop/bot/test.py", line 7, in
data = cur.execute('SELECT * FROM vip_users').fetchall()
File "/usr/lib/python3.8/sqlite3 /dbapi2.py", line 64, in convert_date
return datetime.date(*map(int, val.split(b"-")))
ValueError: invalid literal for int() with base 10: b'23 13:28 :32.725766'

Data in the database:
5fbbbae5b32e9805687440.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
o5a, 2020-11-23
@o5a

It looks like the field in the table was created as a DATE, not a TIMESTAMP, so it tries to convert to a DATE without a time when it's uploaded.
You can either use the correct field type initially, or explicitly specify the type in the request

select time_to_next_pay as "time_to_next_pay [timestamp]" from vip_users

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question