Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 96E2E9FB31B for ; Mon, 5 Feb 2007 12:23:03 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 99893-01 for ; Mon, 5 Feb 2007 12:22:51 -0400 (AST) X-Greylist: delayed 00:23:29.417918 by SQLgrey-1.7.4 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id D4BF49FA306 for ; Mon, 5 Feb 2007 12:22:51 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from mailgate2.urz.uni-halle.de (mailgate2.urz.uni-halle.de [141.48.3.8]) by svr4.postgresql.org (Postfix) with ESMTP id 0C42C5AF93C for ; Mon, 5 Feb 2007 15:59:21 +0000 (GMT) Received: from mserv1.urz.uni-halle.de ([141.48.3.145] helo=mserv1) by mailgate2.urz.uni-halle.de with esmtp (Exim 4.66) id 1HE6FS-00051p-28 for ; Mon, 05 Feb 2007 16:59:18 +0100 Received: from conversion-daemon.mail.uni-halle.de by mail.uni-halle.de (iPlanet Messaging Server 5.2 HotFix 2.14 (built Aug 8 2006)) id <0JCZ00I01YF88J@mail.uni-halle.de> (original mail from sneumann@ipb-halle.de) for pgsql-sql@postgresql.org; Mon, 05 Feb 2007 16:59:17 +0100 (MET) Received: from mail.ipb-halle.de (mail.ipb-halle.de [192.124.243.163]) by mail.uni-halle.de (iPlanet Messaging Server 5.2 HotFix 2.14 (built Aug 8 2006)) with ESMTP id <0JCZ00BF5Z1U1B@mail.uni-halle.de> for pgsql-sql@postgresql.org; Mon, 05 Feb 2007 16:58:42 +0100 (MET) Received: mail.ipb-halle.de 192.168.4.180 from 192.168.1.15 192.168.1.15 via HTTP with MS-WebStorage 6.0.6249 Received: from lathan by mail.ipb-halle.de; Mon, 05 Feb 2007 17:02:21 +0100 Date: Mon, 05 Feb 2007 17:02:21 +0100 From: sneumann Subject: PL/pgsql declaration of string / bit / number with given (variable!) length To: pgsql-sql@postgresql.org Message-id: <1170691341.14733.147.camel@lathan.ipb-sub.ipb-halle.de> Organization: IPB Halle MIME-version: 1.0 X-Mailer: Evolution 2.6.1 Content-type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-DKljXHgx4Q6dG10IF7Uz" X-Scan-Signature: 8eee9948f69ee05a2c1bb535a10baae3 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.002 tagged_above=0 required=5 tests=BAYES_50, UNPARSEABLE_RELAY X-Spam-Level: X-Archive-Number: 200702/44 X-Sequence-Number: 27378 --=-DKljXHgx4Q6dG10IF7Uz Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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=20 with the given size "len", but that breaks with a syntax error: ret :=3D B'0'::bit(len); LINE 1: SELECT B'0'::bit( $1 ) ^ Any suggestion how to return a (bit) string=20 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 :=3D B'0'::bit(10); one :=3D B'1'::bit(10); FOR num IN 0..value-1 LOOP ret :=3D ret | (one >>num); END LOOP; RETURN ret; END; $$ LANGUAGE plpgsql; --=20 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 --=-DKljXHgx4Q6dG10IF7Uz Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQBFx1UNir2msrPI0lQRAs6TAJwL7jXtQyD7qXV/pHIr7Z+RVGQ9QgCcD8kk 19m1jV5OnjvML889bfJo3kc= =hJG2 -----END PGP SIGNATURE----- --=-DKljXHgx4Q6dG10IF7Uz--