casting for bit strings in plpgsql. - Mailing list pgsql-novice

From Celia McInnis
Subject casting for bit strings in plpgsql.
Date
Msg-id 20050405183156.M98363@drmath.ca
Whole thread Raw
List 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

pgsql-novice by date:

Previous
From: "Walker, Jed S"
Date:
Subject: plpgsql - can't get a simple block to execute
Next
From: Tom Lane
Date:
Subject: Re: plpgsql - can't get a simple block to execute