PostgreSQL: Can you create an index in the CREATE TABLE definition?

前端 未结 3 736
既然无缘
既然无缘 2020-12-24 00:11

I want to add indexes to some of the columns in a table on creation. Is there are way to add them to the CREATE TABLE definition or do I have to add them afterward with anot

3条回答
  •  孤城傲影
    2020-12-24 00:29

    There doesn't seem to be any way of specifying an index in the CREATE TABLE syntax. PostgreSQL does however create an index for unique constraints and primary keys by default, as described in this note:

    PostgreSQL automatically creates an index for each unique constraint and primary key constraint to enforce uniqueness.

    Other than that, if you want a non-unique index, you will need to create it yourself in a separate CREATE INDEX query.

提交回复
热议问题