J'ai une table
create table t
(id serial primary key,
name text,
val INTEGER);
insert into t(name, val)
select "user1", x"0001"::INT
union all
select "user1", x"0010"::INT
union all
select "user1", x"0110"::INT
union all
select "user2", x"0001"::INT
Comment puis-je sélectionner des valeurs dans une variable en utilisant l'opération bit pour un nom donné?
create or replace function get_union(
name text,
OUT retval int
)
as $BODY$
begin
-- ?
end
$BODY$ language plpgsql;
Par exemple, la fonction doit renvoyer 111 pour le nom "utilisateur1"
select to_hex(x"0001"::int | x"0010"::int | x"0100"::int);
---
111
Réponses:
1 pour la réponse № 1select to_hex(bit_or(val)), bit_or(val), bit_or(val)::bit(16)
from t
where name = "user1";
to_hex | bit_or | bit_or
--------+--------+------------------
111 | 273 | 0000000100010001