Home > other >  Cast bit(64) to boolean in Postgres
Cast bit(64) to boolean in Postgres

Time:02-17

I know you can cast an int8 to a boolean like so:

int8::int4::boolean

Now I'm trying to cast an int8 to a bit(64), AND that with a bit(64) mask, and then evaluate the entire expression as a boolean (ie. true iff at least one bit is 1).

But bit(64)::int4::boolean doesn't work.

What does?

CodePudding user response:

I see no need for that, since there are bit-wise ooerators:

WHERE intcol & 127 <> 0

CodePudding user response:

Figured it out quickly; might as well share.

In order to cast a bit(64) to a boolean, you can do:

bit(64)::int8::int4::boolean

There must be a better way...

What would be the harm in evaluating a 64-bit expression as a true/false predicate, like in so many programming languages?

  • Related