Skip to content
Advertisement

Does postgres automatically generate an id for every row?

I am new to postgres and SQL in general. I am coming from NoSQL. More specific mongodb. In mongodb every document had a unique id automatically generated by mongodb.

Do postgres rows automatically have a unique id or do you have to generate them yourself?

Advertisement

Answer

You need to define one for yourself:

In a relational database you have to define the primary key yourself, the database does not make assumptions about that. e.g. a link table for a many-to-many relationship usually doesn’t have a generated PK at all:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement