1

I have an array of type character.

For ex: {AA,BB,CC,DD,EE,FF,GG, hh, II, jj,KK}

From the above array i need to extract for ex: from 3rd position to 7th position which is {CC,DD,EE,FF,GG}

Please let me know how to achieve this.

1 Answer 1

2

If you know the positions, you can simple do this:

SELECT myarray[3:7] FROM mytable ...;
Sign up to request clarification or add additional context in comments.

2 Comments

+1, I'd also add that PostgreSQL have 1-based indexing, which is not very common
+1, you can use the unnest(myarray) function to have the array values in separate rows. Note that: It will duplicate the records you have.

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.