Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

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: Tue, 29 Nov 2005 21:46:13 -0500
  • Message-id: <438D1275(dot)7080809(at)dunslane(dot)net>


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



  • References:
    • BIN()
      • From: Christopher Kings-Lynne

Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group