Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a MAX_INT constant in Postgres?

In Java I can say Integer.MAX_VALUE to get the largest number that the int type can hold.

Is there a similar constant/function in Postgres? I'd like to avoid hard-coding the number.

Edit: the reason I am asking is this. There is a legacy table with an ID of type integer, backed by a sequence. There is a lot of incoming rows into this table. I want to calculate how much time before the integer runs out, so I need to know "how many IDs are left" divided by "how fast we are spending them".

like image 882
vektor Avatar asked Feb 09 '16 09:02

vektor


1 Answers

There's no constant for this, but I think it's more reasonable to hard-code the number in Postgres than it is in Java.

In Java, the philosophical goal is for Integer to be an abstract value, so it makes sense that you'd want to behave as if you don't know what the max value is.

In Postgres, you're much closer to the bare metal and the definition of the integer type is that it is a 4-byte signed integer.

like image 141
Nathaniel Waisbrot Avatar answered Nov 15 '22 05:11

Nathaniel Waisbrot