Re: BIN()

From: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BIN()
Date: 2005-11-30 03:04:05
Message-ID: 438D16A5.4020203@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>>create or replace function bin(bigint) returns text language plperl as $$
>>
>> my $arg = $_[0] + 0;
>> my $res = "";
>> while($arg)
>> {
>> $res = ($arg % 2) . $res;
>> $arg >>= 1;
>> }
>> return $res;
>>
>>$$;
>
>
> Any reason not to use sprintf("%b", $_[0])?
>

All very well and good, but it has to be PL/SQL preferably or PL/pgSQL.
I can write it in PL/PGSQL easily enough I guess but I was hoping
there was a neato shortcut.

Chris

In response to

  • Re: BIN() at 2005-11-30 02:57:58 from Michael Fuhr

Browse pgsql-hackers by date

  From Date Subject
Next Message Christopher Kings-Lynne 2005-11-30 03:08:08 Re: BIN()
Previous Message Michael Fuhr 2005-11-30 03:02:51 Re: BIN()