substring extraction

From: Karel Zak - Zakkr <zakkr(at)zf(dot)jcu(dot)cz>
To: pgsql-hackers <pgsql-hackers(at)postgreSQL(dot)org>
Subject: substring extraction
Date: 1999-11-25 18:38:31
Message-ID: Pine.LNX.3.96.991125184601.3411A-100000@ara.zf.jcu.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hi,

I need in the SELECT query extract substring 'cccc' from string
'aaa.bbbbb.cccc.dd.eee' (extract third field from string if
delimiter is '.').

It is easy if I know where is begin/end of 'cccc' and I can
use the substring() function:

select substring('aaa.bbbbb.cccc.dd.eee' from 11 for 4);
substr
------
cccc

But how extract it if I don't know where is position of the second
and third '.'?

Yes, I know the function position() or textpos(), but this return first
a position of the substring...

For this exist nice UN*X command "cut -f3 -d." , but how make it in
SQL?

I ask about it, because I write for me this as new function in C, but
I'm not sure if not exist other (better) way for it.

Karel

------------------------------------------------------------------------------
Karel Zak <zakkr(at)zf(dot)jcu(dot)cz> http://home.zf.jcu.cz/~zakkr/

Docs: http://docs.linux.cz (big docs archive)
Kim Project: http://home.zf.jcu.cz/~zakkr/kim/ (process manager)
FTP: ftp://ftp2.zf.jcu.cz/users/zakkr/ (C/ncurses/PgSQL)
------------------------------------------------------------------------------

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Meskes 1999-11-25 19:25:21 [abhijitc@wipinfo.soft.net: A query...]
Previous Message Bruce Momjian 1999-11-25 18:36:09 Re: [HACKERS] Vacuum