如何在postegres的结果上执行按位运算符? [英] how to perform a bitwise operator on result in postegres?

查看:95
本文介绍了如何在postegres的结果上执行按位运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有几行,并且想对结果执行按位或运算,如何在Postgres 9.x中执行此操作?

If I have several rows, and I would like to perform a bitwise OR on the result, how can I do this in Postgres 9.x ?

例如
我的表包含

e.g. my table contains

Name col1 col2
--------------
John    1    2
Walter  1    1
Ron     1    2

我知道要执行选择语句,以便从列中获得所有(或子集)值的或。

I know would like to perform select statements so that I get OR of all (or a subset of) values from a column.

Eg

select [magical statement OR col1] from table
would give me
1

select [magical statement OR col2] from table
would give me
3

我希望你可以理解我的意思,我无法弄清楚什么才是我想要的。

I hope you can understand what I mean, I cant figure out what the proper term is for what I want.

推荐答案

select bit_or(col1) from table group by col1;

参考(它可能不存在于您的版本中,因此请查看文档):

Reference (it may not be present in your version, so check the documentation):

集合函数-PostgreSQL文档

这篇关于如何在postegres的结果上执行按位运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆