casting for bit strings in plpgsql.

From: "Celia McInnis" <celia(at)drmath(dot)ca>
To: pgsql-novice(at)postgresql(dot)org
Subject: casting for bit strings in plpgsql.
Date: 2005-04-05 19:17:34
Message-ID: 20050405183156.M98363@drmath.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I am having trouble casting from a "BIT VARYING(20)" value to other things.

If len is calculated as being length($1) where $1 is declared as "BIT VARYING
(20)", the following works:

cmd:='select CAST(CAST(CAST(\'101110010\' AS BIT(' || len || ')) AS INTEGER)
AS BIT(' || $2 || ')) AS x';

but I don't know how to use my argument $1 in place of '101110010' (you can
probably see that I'm just trying to calculate the $2 least signficant bits
of $1). If I try:

cmd:='select CAST(CAST(CAST(\'' || $1 || '\' AS BIT(' || len || ')) AS
INTEGER) AS BIT(' || $2 || ')) AS x';

I get:

ERROR: operator is not unique: "unknown" || bit varying.
HINT: Could not chose a best candidate operator. You may need to add explicit
type casts.

How do I do this?

Celia McInnis

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2005-04-05 19:20:40 Re: plpgsql - can't get a simple block to execute
Previous Message Walker, Jed S 2005-04-05 18:53:30 plpgsql - can't get a simple block to execute