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: 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: Wed, 30 Nov 2005 11:04:05 +0800
  • Message-id: <438D16A5(dot)4020203(at)familyhealth(dot)com(dot)au>

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




Home | Main Index | Thread Index

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