is primary key automatically indexed in postgresql?

Ram Talreja picture Ram Talreja · Mar 20, 2017 · Viewed 27.7k times · Source

enter image description here

I have created table name as d with ID column as primary key and then just inserted records as shown in output, but after fetching all records this output still displayed same as order in which records are inserted. but output as a see now not in ordered form.

Answer

maximilianus picture maximilianus · Mar 20, 2017

PostgreSQL automatically creates an index for each unique constraint and primary key constraint to enforce uniqueness. Thus, it is not necessary to create an index explicitly for primary key columns. (See CREATE INDEX for more information.)

Source: Docs