gpt4 book ai didi

python - Sqlite:无法选择具有大整数 id 的行

转载 作者:行者123 更新时间:2023-12-01 05:41:48 26 4
gpt4 key购买 nike

我有一行在 id 列中具有相当大的值 350268180138164200。当我尝试使用

选择它时
select * from my_table where id=350268180138164200

我什么也没得到,但是当我插入 id=222 的行时,我可以毫无问题地选择它。

select *, typeof(id) from my_table 

表明id的数据类型是整数。

更新:我通过更改插入代码摆脱了这个麻烦,这就是它的样子:

conn = lite.connect('my.sqlite')

with conn:
cur = conn.cursor()


cur.execute("INSERT INTO MY_TABLE (ID) "
"VALUES( :id)",
{ 'id' : -here is smth of type = long- } )
conn.commit()

现在我已将其更改为如下所示(并且选择正在工作):

conn = lite.connect('my.sqlite')

with conn:
cur = conn.cursor()


cur.execute("INSERT INTO MY_TABLE (ID) "
"VALUES( CAST(:id AS INTERGER))",
{ 'id' : -here is smth of type = long- } )
conn.commit()

所以我怀疑 python sqlite 模块(或 sqlite lib 本身)正在做一些转换,这与我的目标一致。或者我不知道。

最佳答案

在这里工作:

sqlite> create table t (id integer);
sqlite> insert into t values (350268180138164200);
sqlite> select * from t;
350268180138164200
sqlite> select * from t where id = 350268180138164200;
350268180138164200
sqlite> select *, typeof(id) from t where id = 350268180138164200;
350268180138164200|integer

关于python - Sqlite:无法选择具有大整数 id 的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17361805/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com