Thread: casting for bit strings in plpgsql.

casting for bit strings in plpgsql.

From
"Celia McInnis"
Date:
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