2

I've created a custom range type:

CREATE OR REPLACE FUNCTION smallint_subtype_diff(x smallint, y smallint) RETURNS float8 AS
'SELECT (x - y)::float8' LANGUAGE sql STRICT IMMUTABLE;

CREATE TYPE smallintrange AS RANGE (
    subtype = smallint,
    subtype_opclass = int2_ops,
    subtype_diff = smallint_subtype_diff    -- required by GiST
);

It works fine and I can index it with GiST.

However, I now wish to index an array of this type: smallintrange[]

Regardless of whether I try GiST or GIN, I get this:

CREATE INDEX ix_Vendors_OpenTimes ON public.Vendors USING gin (OpenTimes);

ERROR: data type smallintrange[] has no default operator class for access method "gin" HINT: You must specify an operator class for the index or define a default operator class for the data type.

How do I get this to work?

1 Answer 1

2

The same error message is thrown when you try to index any built-in range types, f.ex. int4range. This is because there is no built-in GIN operator class for array of ranges. (There is no operator class for GiST or SP-GiST either).

You should try to re-structure your data, f.ex. into a one-to-many relationship, where each vendors row can have multiple entry in a (let's say) vendor_ranges, where you can use a simple range (not an array of them). In that context you could index your ranges.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I'm sure it could be extended, but that's a whole other level.

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.