Re: BIN() - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: BIN()
Date
Msg-id 438D1275.7080809@dunslane.net
Whole thread Raw
In response to BIN()  (Christopher Kings-Lynne <chriskl@familyhealth.com.au>)
Responses Re: BIN()  (Michael Fuhr <mike@fuhr.org>)
List pgsql-hackers
here's a plperl version :-)  :

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;

$$;

cheers

andrew



Christopher Kings-Lynne wrote:

> Hi guys,
>
> How would I go about implementing MySQL's BIN() function easily in 
> PL/SQL.
>
> mysql> SELECT BIN(12);
>         -> '1100'
>
> Basically it converts a bigint to a string containing 1's and 0's.
>
> I've tried messing about with bit() types, but those types lack casts 
> to text, etc.  And they are left padded with many zeros.
>
> Any ideas?
>
> Chris
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>       choose an index scan if your joining column's datatypes do not
>       match
>


pgsql-hackers by date:

Previous
From: Christopher Kings-Lynne
Date:
Subject: BIN()
Next
From: Michael Fuhr
Date:
Subject: Re: BIN()