Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why unsigned integer is not available in PostgreSQL?

I came across this post (What is the difference between tinyint, smallint, mediumint, bigint and int in MySQL?) and realized that PostgreSQL does not support unsigned integer.

Can anyone help to explain why is it so?

Most of the time, I use unsigned integer as auto incremented primary key in MySQL. In such design, how can I overcome this when I port my database from MySQL to PostgreSQL?

Thanks.

like image 430
Adrian Hoe Avatar asked Dec 28 '13 01:12

Adrian Hoe


People also ask

Does Postgres support unsigned?

PostgreSQL doesn't support the UNSIGNED attribute, but it an be enforced by using the CHECK constraint. Otherwise, negative values could be inserted in pgsql databases.

How do you declare unsigned?

The data type to declare an unsigned integer is: unsigned int and the format specifier that is used with scanf() and print() for unsigned int type of variable is "%u".

What does unsigned int mean?

An unsigned integer is a 32-bit datum that encodes a nonnegative integer in the range [0 to 4294967295]. The signed integer is represented in twos complement notation. The most significant byte is 0 and the least significant is 3.


1 Answers

It's not in the SQL standard, so the general urge to implement it is lower.

Having too many different integer types makes the type resolution system more fragile, so there is some resistance to adding more types into the mix.

That said, there is no reason why it couldn't be done. It's just a lot of work.

like image 143
Peter Eisentraut Avatar answered Oct 05 '22 17:10

Peter Eisentraut