3

How is PostgreSQL indexing strings and varchars?

Is it indexing the full "string" or only parts of it?

Until now I've assumed that it's using the full string, but never really got it verified.

1 Answer 1

8

It uses the whole string. If you want to use only a part of a string you can always use an index on an expression. Like:

CREATE INDEX some_idx ON tbl (left(col, 10));

left() requires PostgreSQL 9.1 or later. For older versions:

CREATE INDEX some_idx ON tbl (substr(col, 1,10));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.