How do I do this?
How do I do this?
От:
Wei Weng <wweng@kencast.com>
Дата:
I have a table with column filepath with contents that look like the following: filepath ============== /var/log/foo /var/log/bar /var/cache/foo /var/cache/bar /var/foo /var/bar Is there anyway to retrieve the directory information only regarding those filepaths? So that I can get /var/log /var/cache /var as the result of a query? Thanks! (I am using PostgreSQL 7.4) Wei
Re: [despammed] How do I do this?
От:
Andreas Kretschmer <akretschmer@despammed.com>
Дата:
am 23.03.2005, um 12:37:54 -0500 mailte Wei Weng folgendes: > I have a table with column filepath with contents that look like the > following: > > filepath > ============== > /var/log/foo > /var/log/bar > /var/cache/foo > /var/cache/bar > /var/foo > /var/bar > > Is there anyway to retrieve the directory information only regarding those > filepaths? > > So that I can get > > /var/log > /var/cache > /var > test_db=# select * from filepath ; path ----------------/var/log/foo/var/log/bar/var/cache/foo/var/cache/bar/var/foo (5 Zeilen) test_db=# select substring (path, '/.*/') from filepath ; substring -------------/var/log//var/log//var/cache//var/cache//var/ (5 Zeilen) test_db=# select trim(trailing '/'from substring (path, '/.*/')) from filepath ; rtrim ------------/var/log/var/log/var/cache/var/cache/var (5 Zeilen) test_db=# select version(); version ------------------------------------------------------------------------------------------------------PostgreSQL 7.4.7 on i386-pc-linux-gnu, compiled by GCC i386-linux-gcc (GCC) 3.3.5 (Debian 1:3.3.5-5) (1 Zeile) Regards, Andreas -- Andreas Kretschmer (Kontakt: siehe Header) Heynitz: 035242/47212, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net=== Schollglas Unternehmensgruppe ===
Re: How do I do this?
От:
"Greg Sabino Mullane" <greg@turnstep.com>
Дата:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 > I have a table with column filepath with contents that look like the following: .. > Is there anyway to retrieve the directory information only regarding those > filepaths? SELECT rtrim(substring(filepath from '.+/'),'/') FROM mytable; - -- Greg Sabino Mullane greg@turnstep.com PGP Key: 0x14964AC8 200503232033 http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 -----BEGIN PGP SIGNATURE----- iD8DBQFCQhkMvJuQZxSWSsgRAjTaAJ9zmgSOBH/Nre/XMw+JajBni8YyDwCg1DyV Cd5rIhi026KFoFZEFjMOYvI= =V9ov -----END PGP SIGNATURE-----