Postgresql-operators
提供:Dev Guides
PostgreSQL-演算子
PostgreSQLの演算子とは何ですか?
演算子は、比較や算術演算などの操作を実行するために主にPostgreSQLステートメントのWHERE句で使用される予約語または文字です。
演算子は、PostgreSQLステートメントで条件を指定し、ステートメントの複数の条件の接続詞として機能するために使用されます。
- 算術演算子
- 比較演算子
- 論理演算子
- ビットごとの演算子
PostgreSQLの算術演算子
変数 a が2を保持し、変数 b が3を保持すると仮定します-
リンク:/postgresql/postgresql_arithmetic-operators [例]
Operator | Description | Example |
---|---|---|
+ | Addition - Adds values on either side of the operator | a + b will give 5 |
- | Subtraction - Subtracts right hand operand from left hand operand | a - b will give -1 |
* | Multiplication - Multiplies values on either side of the operator | a* b will give 6 |
/ | Division - Divides left hand operand by right hand operand | b/a will give 1 |
% | Modulus - Divides left hand operand by right hand operand and returns remainder | b % a will give 1 |
^ | Exponentiation - This gives the exponent value of the right hand operand | a ^ b will give 8 |
/ | square root | |
/25.0 will give 5 | ||
/ | Cube root | |
/27.0 will give 3 | ||
! | factorial | 5 ! will give 120 |
!! | factorial (prefix operator) | !! 5 will give 120 |
PostgreSQL比較演算子
変数aが10を保持し、変数bが20を保持すると仮定します-
リンク:/postgresql/postgresql_comparison-operators [例を表示]
Operator | Description | Example |
---|---|---|
= | Checks if the values of two operands are equal or not, if yes then condition becomes true. | (a = b) is not true. |
!= | Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. | (a != b) is true. |
<> | Checks if the values of two operands are equal or not, if values are not equal then condition becomes true. | (a <> b) is true. |
> | Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. | (a > b) is not true. |
< | Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. | (a < b) is true. |
>= | Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. | (a >= b) is not true. |
⇐ | Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. | (a ⇐ b) is true. |
PostgreSQLの論理演算子
以下は、PostgresSQLで使用可能なすべての論理演算子のリストです。
link:/postgresql/postgresql_logical-operators [例を表示]
No.
演算子と説明
1
そして
AND演算子を使用すると、PostgresSQLステートメントのWHERE句に複数の条件を含めることができます。
2
NOT演算子は、使用される論理演算子の意味を逆にします。 Eg. 存在しない、間にない、中にないなど これは否定演算子です。
3
OR
OR演算子は、PostgresSQLステートメントのWHERE句で複数の条件を組み合わせるために使用されます。
PostgreSQLビット文字列演算子
ビット演算子はビットに対して機能し、ビットごとの操作を実行します。 &および|の真理値表次のとおりです-
p | q | p & q | p |
---|---|---|---|
q | 0 | 0 | 0 |
0 | 0 | 1 | 0 |
1 | 1 | 1 | 1 |
1 | 1 | 0 | 0 |
A = 60であると仮定します。およびB = 13;今バイナリ形式では、次のようになります-
A = 0011 1100
B = 0000 1101