2

I am working on a Rails app, that stores data in a Postgresql 9.4 database, the products table has a column images which is an array, I'd like to get the products that have no images, i.e. array_length(images) = 0. Is it possible to create an index on this condition? i.e on the length of the array.

2
  • What is the type of images? Is it a BLOB? Commented Aug 10, 2016 at 18:27
  • it's of type array, it's a Postgresql non standard type, it just contains the urls of the images. not the images themselves. Commented Aug 10, 2016 at 19:40

1 Answer 1

2

Sure, you can create an expression index:

CREATE INDEX ON products ((array_length(images));
Sign up to request clarification or add additional context in comments.

1 Comment

You should accept this answer if it works @NafaaBoutefer

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.