简体   繁体   English

PostgreSQL获取字符串的一部分

[英]PostgreSQL fetch a part of string

I am storing a log like this: 我正在存储这样的日志:

10.03.2015 11:45:29-JAQ -- Updated Following Information
Mobile Updated From 0 to 0502770020</br>
Company Industry Id Updated From 747 to 753</br>
Name Updated from futurehomes to futurehomesdubai </br>
Company Head Office Updated From 0 to 1</br>
Company Telephone Updated From 8008436699 to
Company Comments Updated From Offices and Hotel (Under Construction) to  Offices and Hotel (Under Construction) info@futurehomesdubai.com futurehomesdubai.com</br>
Company Toll Free No Updated From to 800-8436699</br>
Company(139618) Industry Sub Section Updated </br>

I am storing this in a text field. 我将其存储在文本字段中。 From this I need to display only Name Updated from futurehomes to futurehomesdubai section. 因此,我只需要显示从futurehomes更新为futurehomesdubai的名称部分。 the futurehomes to futurehomesdubai will change according to company names. Futurehomesdubai的futurehomes将根据公司名称而更改。 How can I do this? 我怎样才能做到这一点?

with the following as example: 以以下为例:

create table logs(tlog text);

insert into logs values ('Mobile Updated From 0 to 0502770020</br>Company Industry Id Updated From 747 to 753</br>Name Updated from futurehomes to futurehomesdubai </br>Company Head Office Updated From 0 to 1</br>Company Telephone Updated From 8008436699 to
Company Comments Updated From Offices and Hotel (Under Construction) to  Offices and Hotel (Under Construction)info@futurehomesdubai.com futurehomesdubai.com</br>Company Toll Free No Updated From to 800-8436699</br>Company(139618) Industry Sub Section Updated </br>');

and the select should be 选择应该是

select * 
from (
     select unnest(regexp_split_to_array(tlog,'</br>')) col 
     from logs
     )t
where col ilike 'Name Updated%'

Result: 结果:

col                                                
-------------------------------------------------- 
Name Updated from futurehomes to futurehomesdubai

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM