Search code examples
postgresqlprimary-keypostgresql-9.3

Can a primary key in postgres have zero value?


There is one table at my database that have a row with ID equals to 0 (zero). The primary key is a serial column.

I'm used to see sequences starting with 1. So, is there a ploblem if i keep this ID as zero?


Solution

  • The Serial data type creates integer columns which happen to auto-increment. Hence you should be able to add any integer value to the column (including 0).

    From the docs

    The type names serial and serial4 are equivalent: both create integer columns.

    ....(more about Serial) we have created an integer column and arranged for its default values to be assigned from a sequence generator

    http://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-SERIAL