From: sneumann <sneumann@ipb-halle.de>
To: pgsql-sql@postgresql.org
Subject: PL/pgsql declaration of string / bit / number with given (variable!) length
Date: Mon, 05 Feb 2007 17:02:21 +0100
Message-ID: <1170691341.14733.147.camel@lathan.ipb-sub.ipb-halle.de> (raw)
Hi,
I have a PL/pgsql function that creates a certain bit string
based on the parameters. Things work fine if I use bit(10)
throughout the function. Now I'd like to return a bit string
with the given size "len", but that breaks with a syntax error:
ret := B'0'::bit(len);
LINE 1: SELECT B'0'::bit( $1 )
^
Any suggestion how to return a (bit) string
of user-defined length ?
Thanks in advance,
Yours,
Steffen
CREATE OR REPLACE FUNCTION unarystr(
value integer,
len integer
) RETURNS bit(10) AS $$
DECLARE
ret bit(10);
one bit(10);
BEGIN
ret := B'0'::bit(10);
one := B'1'::bit(10);
FOR num IN 0..value-1 LOOP
ret := ret | (one >>num);
END LOOP;
RETURN ret;
END;
$$ LANGUAGE plpgsql;
--
IPB Halle AG Massenspektrometrie & Bioinformatik
Dr. Steffen Neumann http://www.IPB-Halle.DE
Weinberg 3 http://msbi.bic-gh.de
06120 Halle New phone number !
Tel. +49 (0) 345 5582 - 1470
+49 (0) 345 5582 - 0
sneumann(at)IPB-Halle.DE Fax. +49 (0) 345 5582 - 1409
Attachments:
signature.asc (application/pgp-signature, 190B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: sneumann@ipb-halle.de
Subject: Re: PL/pgsql declaration of string / bit / number with given (variable!) length
In-Reply-To: <1170691341.14733.147.camel@lathan.ipb-sub.ipb-halle.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox