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?
In case of an array, the address of the n th element can be computed since an array is allocated in contiguous memory locations. Thus, an element of an array can be accessed in O(1) time. In the case of a linked list, to access the n th element, you will need to traverse the linked list to reach the n th element.
The :nth-child() pseudo-class takes a single argument that describes which elements should be matched. Note that element indices are 1-based when using :nth-child() . You can narrow things down by only matching an element of a specific type, e.g. the second positioned div element. index.js. Copied!
select (string_to_array('1,2,3,4',','))[2];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With