étale-cohomology
étale-cohomology

Reputation: 1861

Cast bit(64) to boolean in Postgres

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?

Upvotes: 0

Views: 1310

Answers (2)

Laurenz Albe
Laurenz Albe

Reputation: 246308

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

WHERE intcol & 127 <> 0

Upvotes: 2

&#233;tale-cohomology
&#233;tale-cohomology

Reputation: 1861

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?

Upvotes: 0

Related Questions