Re: SELECT question
От | Alvaro Herrera |
---|---|
Тема | Re: SELECT question |
Дата | |
Msg-id | 20031104213404.GB12410@dcc.uchile.cl обсуждение исходный текст |
Ответ на | SELECT question (Alex <alex@meerkatsoft.com>) |
Список | pgsql-general |
On Tue, Nov 04, 2003 at 07:54:54PM +0900, Alex wrote: > I have a bit string , 7 bits, every bit representing a day of the week. > e.g. 1110011. > Is there and easy way where I can translate/format that string in a query. > I want to give the string back with a '-' for every 0 and the first char > of the Day for every '1'. > example 1100111 = SM--TFS. A simple perl function: sub mybits { my $bits = shift; my $ret = ""; foreach my $i (0 .. 6) { substr($ret, $i, 1, (substr($bits, $i, 1) =~ /1/ ? (qw(S M T W T F S))[$i] : "-")); } return $ret; } $ ./test.pl 1001011 S--W-FS You can of course use it with plperl. -- Alvaro Herrera (<alvherre[a]dcc.uchile.cl>) Hi! I'm a .signature virus! cp me into your .signature file to help me spread!
В списке pgsql-general по дате отправления: