mySQL 5.0.45 LAST_INSERT_ID() 和大于有符号整数的值

发布于 2024-09-13 02:12:53 字数 231 浏览 3 评论 0原文

我正在尝试在已移动超过有符号 int 值 2147483647 的自动递增索引上使用 LAST_INSERT_ID。此列是无符号 int。但是,LAST_INSERT_ID() 返回无效的负值。通过研究,我发现了一些评论,表明这就是这个函数的本质。但我找不到它的正式记录。有一些可以追溯到几年前的错误报告仍然处于开放状态。

所以我需要知道这是否确实是一个已知的错误和/或我是否可以对此做些什么。我需要将 mySQL 升级到新版本吗?

I'm attempting to use LAST_INSERT_ID on an auto incremented index that has moved past the signed int value 2147483647. This column is an unsigned int. However, LAST_INSERT_ID() is returning an invalid negative value. Researching this, I've found a couple comments indicating this is the nature of this function. But I cannot find it officially documented. There are some bug reports dating back several years that are still open.

So I need to know if this is in fact a known bug and/or if there's something I can do about this. Do I need to upgrade mySQL to a newer version?

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

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

发布评论

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

评论(2

夜无邪 2024-09-20 02:12:54

从问题的评论中我假设您正在使用 PHP。 (当前未标记为“php”相关)。 我在这里加 2 美分

我正在尝试在已移动超过有符号整型值 2147483647 的自动递增索引上使用 LAST_INSERT_ID。此列是无符号整型。但是,LAST_INSERT_ID() 返回无效的负值。通过研究,我发现了一些评论,表明这就是这个函数的本质。但我找不到它的正式记录。有一些可以追溯到几年前的错误报告仍然处于开放状态。

mySQLLAST_INSERT_ID 函数将从 AUTO_INCRMENT 上的最新 INSERT 返回 ID > 列(在当前连接上),因此,如果您的列是一个INTEGER UNSIGNED,就像您所说的那样,它可能返回大于2147483647的值。这是正确的行为。

所以我需要知道这是否确实是一个已知的错误和/或我是否可以对此做些什么。我需要将 mySQL 升级到新版本吗?

mySQL 数据类型与您选择在 PHP 上使用的表示形式关系不大,因此问题不在 mySQL 服务器中。如果您的PHP安装无法处理如此大的数字,那么您可以将其视为字符串(Shadow Radiance说)。

I'm assuming you are using PHP from the comments on the question. (is not currently tagged as "php" related). I'll just add my 2 cents here

I'm attempting to use LAST_INSERT_ID on an auto incremented index that has moved past the signed int value 2147483647. This column is an unsigned int. However, LAST_INSERT_ID() is returning an invalid negative value. Researching this, I've found a couple comments indicating this is the nature of this function. But I cannot find it officially documented. There are some bug reports dating back several years that are still open.

mySQL's LAST_INSERT_ID function will return the ID from the latest INSERT on an AUTO_INCREMENT column (on the current connection) so, if your column is an INTEGER UNSIGNED like you said, it could return values greater than 2147483647. This is the correct behavior.

So I need to know if this is in fact a known bug and/or if there's something I can do about this. Do I need to upgrade mySQL to a newer version?

The mySQL data type has little to do with the representation you chose to use on PHP so the problema is not in the mySQL server. If your PHP installation can't handle numbers so BIG, then you can treat it as a string (Shadow Radiance said).

野侃 2024-09-20 02:12:53

我对此不是 100% 确定,但由于您只需要 ID,而不对其进行任何数学运算,您是否可以将其作为字符串处理,并让您的 select 语句将数字转换为字符串?

I'm not 100% sure on this, but since you just need the ID and not to do any mathematical operations on it, could you perhaps process it as a string and have your select statement convert the number to a string?

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