基本 SELECT 找不到条目

发布于 2024-12-11 10:57:52 字数 439 浏览 0 评论 0原文

我可能在这里犯了一个愚蠢的初学者错误,但 SQL 不是我的强项之一。

我正在尝试修改一个简单的 SQLite DB(在 SQLite Manager 中),但似乎无法做到这一点,直到我弄清楚为什么我无法让此 select 语句返回。

SELECT *
FROM facts
WHERE id = -9215979828305747000

没有抛出任何错误,也没有返回任何内容,无论它是表中的第一个条目。我也

SELECT *
FROM facts
WHERE CAST(facts.id AS INTEGER) = CAST('-9215979828305747000' AS INTEGER)

再次尝试什么也没有。

我在浏览窗口中看到该值,但无法在特定搜索中获取它。发生这种情况是因为值长度吗?

I'm probably making a stupid beginner mistake here but SQL isn't one of my strong points.

I'm trying to modify a simple SQLite DB (in SQLite Manager) but can't seem to do it until I figure out why I can't get this select statement to return.

SELECT *
FROM facts
WHERE id = -9215979828305747000

threw no error and returned nothing regardless of the fact that its the first entry on the table. I also tried

SELECT *
FROM facts
WHERE CAST(facts.id AS INTEGER) = CAST('-9215979828305747000' AS INTEGER)

again nothing.

I see the value in the browse window but can't get it in a specific search. Is this happening because of value length?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我一向站在原地 2024-12-18 10:57:52

-9215979828305747000 大于 Int32 的最大值 (2147483647),所以我猜facts.id 不是整数。检查您的数据类型并相应地进行 CAST。

也许它是一个字符串?

SELECT *
FROM facts
WHERE id = '-9215979828305747000'

-9215979828305747000 is bigger than the maximum value for an Int32 (2147483647), so I guess facts.id is not an Integer. Check your datatype and CAST accordingly.

Perhaps it is a string?

SELECT *
FROM facts
WHERE id = '-9215979828305747000'
为人所爱 2024-12-18 10:57:52

我做了这个测试:

CREATE TABLE "test" (
    "id" INTEGER PRIMARY KEY NOT NULL,
    "name" TEXT
)

insert into test values (1, "tttt")
insert into test values (-9215979828305747000, "OO")


select name from test where id = -9215979828305747000'

> "OO"

所以它似乎在一个全新的表中工作。问题显然不在sql select或key或表定义中。

尝试获取临时表中的数据:

insert into table_copy values (select * from facts)

I did this test :

CREATE TABLE "test" (
    "id" INTEGER PRIMARY KEY NOT NULL,
    "name" TEXT
)

insert into test values (1, "tttt")
insert into test values (-9215979828305747000, "OO")


select name from test where id = -9215979828305747000'

> "OO"

So it seems to work in a fresh new table. The problem is clearly not in the sql select or key or table definition.

Try to get the data in some temporary table :

insert into table_copy values (select * from facts)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文