Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an "Implicit Database Sequence"?

I pushed a Ruby on Rails test application up to Heroku and, after running the command heroku run rake db:migrate, received a notification that says:

NOTICE: CREATE TABLE will create implicit sequence "microposts_id_seq" for serial column "microposts.id"

What is an implicit sequence? And, in this case, is a "serial column" another way to refer to a primary key?

like image 754
Trent Scott Avatar asked Nov 13 '22 14:11

Trent Scott


1 Answers

Your table contains a column which is defined as serial which is just a shorthand for an integer column which default value is taken from a sequence. In order to do that, PostgreSQL automatically creates a sequence that is bound to that column. The message merely tells you that such a sequence was created.

If you didn't explicitely define a serial column, you probably defined it as "autoincremen" or whatever the Ruby term for that is.

For more details please read the manual: http://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-SERIAL

like image 79
a_horse_with_no_name Avatar answered Nov 15 '22 04:11

a_horse_with_no_name