Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account

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

1

71 views

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);

asked June 4, 2011 4:58 pm CDT
posted via StackOverflow

2 Answers

4
Best answer
 

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.

answered June 4, 2011 5:24 pm CDT
2
 

No.

However, you can create unique indexes in the create, but that's because they are classed as constraints. You can't create a "general" index.

answered June 4, 2011 5:24 pm CDT

Your answer

Join with account you already have


Sign in with Twitter account
Sign in with Facebook account
Sign in with Google Friend Connect

Preview
Similar questions