Re: BIN()

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
Cc: Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BIN()
Date: 2005-11-30 02:46:13
Message-ID: 438D1275.7080809@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
>

In response to

  • BIN() at 2005-11-30 02:15:07 from Christopher Kings-Lynne

Responses

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

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Fuhr 2005-11-30 02:57:58 Re: BIN()
Previous Message Alvaro Herrera 2005-11-30 02:30:50 Re: Please let us know if you will come to the PostgreSQL Anniversary