postgresql 获取从“string_to_array()”函数返回的数组的第 N 个元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11831555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 23:38:50  来源:igfitidea点击:

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

arrayspostgresql

提问by iso_9001_

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,

我正在寻找一种方法来访问数组的第 N 个元素,这是string_to_array()PostgreSQL中函数的结果。例如,

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'.

假设一个单元格包含字符串值: "A simple example" 。如果我使用string_to_array()函数,我将有一个包含三个字符串的数组('A','simple','example')。现在,没有存储(我的意思是,即时)我想访问这个数组的第二个元素,它是“简单的”。

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?

有没有办法做到这一点?

回答by devanand

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