我想在创建时向表中的某些列添加索引。有没有办法将它们添加到CREATE TABLE定义中,还是我必须在之后再添加另一个查询?
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 another query?
CREATE INDEX reply_user_id ON reply USING btree (user_id);推荐答案
似乎没有任何指定方法 CREATE TABLE 语法的索引。但是,PostgreSQL确实会默认为唯一约束和主键创建索引,如此说明:
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会自动为每个唯一约束和主键约束创建索引
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.
更多推荐
PostgreSQL:可以在CREATE TABLE定义中创建索引吗?
发布评论