From: | Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl> |
---|---|
To: | Alex <alex(at)meerkatsoft(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: SELECT question |
Date: | 2003-11-04 21:34:04 |
Message-ID: | 20031104213404.GB12410@dcc.uchile.cl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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!
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2003-11-04 21:35:55 | Re: INSERT performance |
Previous Message | Tom Lane | 2003-11-04 21:26:38 | Re: Using SUBSELECT in CHECK expressions |