Search Postgresql Archives

Re: Spliting a string in plpgsql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Jasbinder Singh Bali <jsbali@xxxxxxxxx> schrieb:
>> I'm writing a function in plpgsql and i need to do the following:
>> 
>> I have a string in the following format.
>> 
>> mail.yahoo.com
>> 
>> In this string, i need to figure out the number of dots in it and
split the
>> string into two on last but one dot.
> 
> Number of dots:
> 
> test=*# select 
> length(regexp_replace('mail.yahoo.com','[^\.]','','g'));
>  length
> --------
>       2
> (1 row)

I think that this is the desired split:

test=> SELECT regexp_replace('mail.yahoo.com',
E'^(.*)\\.([^.]*\\.[^.]*)$', E'\\1');
 regexp_replace 
----------------
 mail
(1 row)

test=> SELECT regexp_replace('mail.yahoo.com',
E'^(.*)\\.([^.]*\\.[^.]*)$', E'\\2');
 regexp_replace 
----------------
 yahoo.com
(1 row)

Yours,
Laurenz Albe


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux