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*
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
A&B = 0000 1100
A | B = 0011 1101
〜A = 1100 0011
リンク:/postgresql/postgresql_bitwise-operators [例を表示]
PostgreSQLでサポートされているビットごとの演算子は、次の表に記載されています-
[cols="^,,^",options="header",]
|===
|Operator |Description |Example |& |Binary AND Operator copies a bit to the result if it exists in both operands. |(A & B) will give 12 which is 0000 1100 || |Binary OR Operator copies a bit if it exists in either operand. |(A | B) will give 61 which is 0011 1101 |~ |Binary Ones Complement Operator is unary and has the effect of 'flipping' bits. |(~A ) will give -61 which is 1100 0011 in 2's complement form due to a signed binary number. |<< |Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. |A << 2 will give 240 which is 1111 0000 |>> |Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. |A >> 2 will give 15 which is 0000 1111 |# |bitwise XOR. |A # B will give 49 which is 0100 1001
|===