MERGE INTO users u
USING (VALUES($1, $2, $3)) v
ON v.column1 = u.steamid
WHEN NOT MATCHED
INSERT (balance, steamid, name, avatar) VALUES (0, v.column1, v.column2, v.column3)
WHEN MATCHED
UPDATE SET name =v.column2;
select case when status in ('ACTIVE', 'ONLINE') then 1
when status in ('DISCHARGED', 'WARN', 'ABNORMAL') then 2
end status_type,
Count(*) cnt
from sensor_instances
where groupid = 18
group by status_type