Get Nth element of an array that returns from "string_to_array()" function

ArraysPostgresql

Arrays Problem Overview


I am searching for a way to access to the Nth element of an array which is a result of string_to_array() function in PostgreSQL. For example,

Assume that a cell contains the string value: "A simple example" . If I use string_to_array() function, I will have an array of three strings as ('A','simple','example'). Now, without storing (I mean, on the fly) I want to access the 2nd element of this array, which is 'simple'.

During my googling, I saw an example to access the last element of the array but this barely solved my problem.

Is there a way to do this?

Arrays Solutions


Solution 1 - Arrays

select (string_to_array('1,2,3,4',','))[2];

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questioniso_9001_View Question on Stackoverflow
Solution 1 - ArraysdevanandView Answer on Stackoverflow