What is the difference between the serial and integer data type in PostgreSQL?

2

I am creating a database in PostgreSQL and struck the question how can I create in the table the field ID with AUTO_INCREMENT, searching the internet I found some examples with the ID field with SERIAL data type and others with INTEGER data type. / p>

What is the difference between these 2 data types and which one can we use to be our ID with AUTO_INCREMENT in the PostgreSQL database?

    
asked by anonymous 06.07.2017 / 17:13

1 answer

2

When you define a field as serial , the bank creates a column of type integer or biginteger with an associated sequence , it is responsible for increasing the number. If you create a field only as integer it is up to the programmer to log the logic of how it will increment or create a sequence in hand, via application, etc.

    
06.07.2017 / 17:18