Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I can't use directly uuid with gist index

CREATE INDEX idx_leaderboads_values_gist
  ON leaderboard_entry
  USING gist
  (id_leaderboard , value);

And I got this error:

ERROR: data type uuid has no default operator class for access method "gist"

HINT: You must specify an operator class for the index or define a default operator class for the data type.

share|improve this question

1 Answer 1

Normally I would suggest the additional module btree_gist, but the type uuid is not covered by it.

In theory, since a UUID is a 128-bit quantity (per documentation), the most efficient way would be to convert it to two bigint or float8 for the purpose of the index. But none of these casts are defined in standard Postgres.

I found a stab in that direction in the pqsql-hackers list, but it seems unsuccessful.

The remaining option is a functional GiST index on the text representation:

CREATE INDEX idx_leaderboads_values_gist
ON leaderboard_entry USING gist (id_leaderboard, cast("value" AS text));

To make use of this functional index, queries must match that expression. You can use the shorthand "value"::text in queries (but not in the index definition without adding more parentheses).

Aside: do not use value as column name it's a reserved word in standard SQL.

The question is: why do you need the GiST index. The best solution depends on the objective.

share|improve this answer
    
I need to lookup value around one value in the leaderboard and I want to avoid to create two query to do it. – xjodoin Mar 31 '14 at 12:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.