psycopg2.errors.NumericValueOutOfRange:整数超出范围

问题描述 投票:0回答:1

我正在尝试将数据插入用户表中:

cursor.execute("""CREATE TABLE IF NOT EXISTS users (
        name TEXT NOT NULL, 
        id BIGINT NOT NULL, 
        xp INT NOT NULL
    )""")
    for guild in bot.guilds:
        for member in guild.members:
            if cursor.execute(f"SELECT id FROM users WHERE id = {member.id}") is None:
                if member.id not in bots:
                    cursor.execute("INSERT INTO users (name, id, xp) VALUES ('{}', {}, {});".format(member, member.id, 0))
    connect.commit()
    connect.close()

但我不断收到错误:

File "C:\Users\belog\hat_dispenser\main.py", line 58, in on_ready
    cursor.execute("INSERT INTO users (name, id, xp) VALUES ('{}', {}, {})".format(member, member.id, 0))
psycopg2.errors.NumericValueOutOfRange: integer out of range

我尝试为列“id”指定数据类型,例如 BIGINT、INT、BIGSERIAL、SERIAL。但我仍然收到“整数超出范围”错误。怎么解决?

python postgresql psycopg2
1个回答
0
投票

您可能确信此错误是从“id”列中产生的,可能是“xp”。 我有和你一样的问题,但解决方案是我将“BigInteger”类型指定给错误的列

© www.soinside.com 2019 - 2024. All rights reserved.