从postgresql中的语句中提取第一个元素

时间:2017-08-30 06:38:40

标签: sql postgresql extract

我的表中有一个名为people的列,这是一个声明。我只需从该列中提取名称。

人:

Ramu is a good dancer.
Raj is the highest scorer in maths.

我需要从这些语句中仅提取名称(ramu,raj)。 提示:is之前的名称,因为所有语句在这里都有一个单词is

我不知道如何在postgresql中提取

1 个答案:

答案 0 :(得分:0)

使用split_part():

with people(statement) as (
values
    ('Ramu is a good dancer.'),
    ('Raj is the highest scorer in maths.')
)

select split_part(statement, ' ', 1) as name
from people;

 name 
------
 Ramu
 Raj
(2 rows)