[Solved] Postgres: integer out of range

I’m running the following query:

WITH match_team_vals(match_id, team_id, is_radiant) AS (
(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:

SELECT nextval('dota_match_team_id_seq')
returns 31
Solution #1:

Consider altering your table to use a bigger integer (see here for details:

I think the problem is, that your match_id and team_id are of type integer and you try to insert the value 2281450916, but integer’s maximum is 2147483647

Respondent: 23tux
Solution #2:

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.

  SELECT setval('dota_match_team_id_seq' , 100000000);
Respondent: Shubham Batra
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy