postgresql Postgres:整数超出范围

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36513168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:14:06  来源:igfitidea点击:

Postgres: integer out of range

sqlpostgresql

提问by janderson

I'm running the following query:

我正在运行以下查询:

WITH match_team_vals(match_id, team_id, is_radiant) AS (
VALUES 
(2281450916, 2783913, true),
(2281450916, 2538753, false)
)

INSERT INTO dota_match_team(match_id, team_id, is_radiant)
SELECT match_id, team_id, is_radiant
FROM match_team_vals
RETURNING id AS lineup_id

on this table:

在这张桌子上:

CREATE TABLE dota_match_team
(
  id serial NOT NULL,
  match_id integer NOT NULL,
  team_id integer,
  is_radiant boolean NOT NULL,
  CONSTRAINT dota_match_teams_pkey PRIMARY KEY (id)
)

The error message I get is

我得到的错误信息是

ERROR: integer out of range
SQL state: 22003

I've tried casting the match_id and team_id to bigint. Also looking online I see that people have this issue with the serial hitting the upper limit of integers. This doesn't seem to be the case:

我试过将 match_id 和 team_id 转换为 bigint。也在网上看我看到人们有这个问题,串行达到整数的上限。情况似乎并非如此:

SELECT nextval('dota_match_team_id_seq')
returns 31

回答by 23tux

Consider altering your table to use a bigger integer (see here for details: http://www.postgresql.org/docs/9.1/static/datatype-numeric.html).

考虑更改您的表以使用更大的整数(有关详细信息,请参见此处:http: //www.postgresql.org/docs/9.1/static/datatype-numeric.html)。

I think the problem is, that your match_idand team_idare of type integerand you try to insert the value 2281450916, but integer's maximum is 2147483647

我认为问题是,您的match_idteam_id属于类型integer并且您尝试插入值2281450916,但整数的最大值是2147483647

回答by Shubham Batra

You can run this query:

您可以运行此查询:

ALTER TABLE dota_match_team alter column match_id type bigint;

this type cast solve the error for match_id. if you thinkIt is error of serial limit then you can also do.

这种类型转换解决了 match_id 的错误。如果您认为这是串行限制错误,那么您也可以这样做。

  SELECT setval('dota_match_team_id_seq' , 100000000);