What is the difference between (int4range type) and (integer). Postgres launch this error in INSERT

Viewed 4966

I want to insert a new row into this table:

table: AUTHOR (id int4range, name characterVarying[])

script:

insert into "EDITORIAL" values (3,'testing');

but postgres says:

...is of type int4range but the expression is of type integer

I tried with 1,2,3...100,200..1000...etc and some postgres page says:

name: integer   aliases: int, int4

is integer = int4 ? or what is int4range?

2 Answers

It is a range of integers. Try

insert into "EDITORIAL" values ('[1,10]','testing');

An integer stores a single whole number. Integer is stored as 4 bytes and can be a whole number between -2147483648 and +2147483647.

An int4range is a data type that represents a min and max value. An example would be a price range for a car. Imagine you want to store the fact that a particular model car can be purchased for anything between $1000 and $2000, you could represent that as two columns storing the min and max or a more accurate way is to use the built in range types.

https://www.postgresql.org/docs/10/static/rangetypes.html

Related