Consultez le docs on bit operators pour pg.
essentiellement &
ne fonctionne que sur deux comme types (généralement peu ou int), alors model_mask
devra être CAST
ed de varchar à peu comme quelque chose de raisonnable ou int:
models_mask::int & 1
-ou-models_mask::int::bit & b'1'
Vous pouvez savoir quels types d'opérateur travaille avec l'aide \doS
dans psql
pg_catalog | & | bigint | bigint | bigint | bitwise and
pg_catalog | & | bit | bit | bit | bitwise and
pg_catalog | & | inet | inet | inet | bitwise and
pg_catalog | & | integer | integer | integer | bitwise and
pg_catalog | & | smallint | smallint | smallint | bitwise and
Voici un exemple rapide pour plus d'informations
# SELECT 11 & 15 AS int, b'1011' & b'1111' AS bin INTO foo;
SELECT
# \d foo
Table "public.foo"
Column | Type | Modifiers
--------+---------+-----------
int | integer |
bin | "bit" |
# SELECT * FROM foo;
int | bin
-----+------
11 | 1011
Excellent! Merci pour la solution et l'explication. –