8

I have a PostgreSQL table that looks like this:

CREATE TABLE items (
    name TEXT NOT NULL,
    value TEXT NOT NULL,
    PRIMARY KEY (name, value)
);

I frequently do a query to see what values are available:

SELECT DISTINCT value FROM items;

How do I create an index in PostgreSQL that the above query to not have to iterate over all of the items table?

1 Answer 1

13

Using a completely different query you can force PostgreSQL to use an index and get the equivalent of DISTINCT column..

https://wiki.postgresql.org/wiki/Loose_indexscan

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.