2017-08-30 91 views
0

我的表中有一個名爲people的列,它是一個語句。我只需要從該列中提取名稱。從postgresql中的語句中提取第一個元素

人:

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

我需要提取這些聲明只是名稱(瑞木,拉吉)。 提示:is之前的名字,因爲所有的陳述在這裏有一個詞is

我沒怎麼在PostgreSQL中提取

回答

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) 
相關問題