Problem with creating an index.

21 views
Skip to first unread message

Manoj Waikar

unread,
May 30, 2011, 11:53:29 AM5/30/11
to lobos-...@googlegroups.com
Hi,

If I run -

(create db (table :users (integer :id :unique)
                                                       (varchar :name 255)
                                                       (index :users :idx_name [:name])))

I get an exception - java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Keyword

If I run -

(create db (table :users (integer :id :unique)
                                                       (varchar :name 255)
                                                       (index :users [:idx_name] [:name])))

I get this error - ERROR: column "idx_name" does not exist
because the following sql statements get generated -

CREATE TABLE "users" ("name" VARCHAR(255), "id" INTEGER, CONSTRAINT "users_unique_id" UNIQUE ("id"))
CREATE INDEX "users" ON "users" ("idx_name")

and if I don't give any name to the index -

(create db (table :users (integer :id :unique)
                                                       (varchar :name 255)
                                                       (index :users [:name])))

I get the error - ERROR: relation "users" already exists

and the following statements get generated -

CREATE TABLE "users" ("name" VARCHAR(255), "id" INTEGER, CONSTRAINT "users_unique_id" UNIQUE ("id"))
CREATE INDEX "users" ON "users" ("name")

so it seems, there is no way to generate a named index, unless I am doing something wrong.

Please let me know.

Thanks,
Manoj.

Nicolas Buduroi

unread,
May 30, 2011, 12:58:34 PM5/30/11
to lobos-...@googlegroups.com
When defining an index as part of a table definition, you must not give the table name, only the optional index name and specs.


(create db (table :users (integer :id :unique)
                                                       (varchar :name 255)
                                                       (index :idx_name [:name])))

That's because the table macro thread through its element passing a record that represent the table as the first argument.

I just realized the documentation was a little bit confusing on that subject, I'll improve it for the next release.

Manoj Waikar

unread,
May 31, 2011, 9:26:54 AM5/31/11
to lobos-...@googlegroups.com
Thanks Nicolas.
Reply all
Reply to author
Forward
0 new messages