Describes the built-in operators available in Postgres.
Postgres にて使用可能な組み込み演 算子について説明します。
Postgres provides a large number of built-in operators on system types. These operators are declared in the system catalog pg_operator. Every entry in pg_operator includes the name of the procedure that implements the operator and the class OIDs of the input and output types.
Postgres はシステム型に対して多くの 組み込み演算子を提供しています。これらの演算子はシステムカタロ グ pg_operator で定義されています。pg_operator の各エントリは、 演算子を実装したプロシージャ名と入出力の型に関する OIDs クラスを含んでいます。
To view all variations of the "||" string concatenation operator, try
文字列連結演算子 "||" の全種類を表示したい場合は、以下 を入力します。
SELECT oprleft, oprright, oprresult, oprcode FROM pg_operator WHERE oprname = '||'; oprleft|oprright|oprresult|oprcode -------+--------+---------+------- 25| 25| 25|textcat 1042| 1042| 1042|textcat 1043| 1043| 1043|textcat (3 rows)
Users may invoke operators using the operator name, as in:
ユーザは次のように演算子名を使って演算子を使用することもでき ます。
select * from emp where salary < 40000;Alternatively, users may call the functions that implement the operators directly. In this case, the query above would be expressed as: 他にも、ユーザは演算子を実装した関数を直接呼び出すこともでき ます。この場合、上の問い合わせは次のように表すことになります。
select * from emp where int4lt(salary, 40000);
psql has a command (\dd) to show these operators.
psql には、演算子を表示するコマンド ( \dd )があります。 (訳注: \do コマンドの間違いです。)
Operators have a precedence which is currently hardcoded into the parser. Most operators have the same precedence and are left-associative. This may lead to non-intuitive behavior; for example the boolean operators "<" and ">" have a different precedence that the boolean operators "<=" and ">=".
演算子には優先順位があります。現在それはパーサのコードに直接記 述されています。ほとんどの演算子は同じ優先順位を持ち、左から評 価されていきます。この優先順位が原因で、思いがけない振舞いをする ことがあります。例えば、ブール演算子 "<" と ">" という組は、 ブール演算子 "<=" と ">=" の組が持つ優先順位と異なる優先順 位を持っています。
Table 4-1. 演算子の順序(優先順位の高い順)
要素 | 優先順位 | 説明 |
---|---|---|
UNION | 左 | SQL select を構築する |
:: | Postgres における型キャスト | |
[ ] | 左 | 配列の区切り文字 |
. | 左 | テーブル/カラムの区切り文字 |
- | 右 | 単項負数 |
; | 左 | 文の終端、対数 |
: | 右 | 指数 |
| | 左 | 間隔の開始点 |
左 | 乗算、除算 | |
+ - | 左 | 加算、減算 |
IS | TRUE、FALSE、NULL かどうかを試験する。 | |
ISNULL | NULL かどうかを試験する。 | |
NOTNULL | 非 NULL かどうかを試験する。 | |
(その他全ての演算子) | 固有、ユーザ定義 | |
IN | メンバーシップの設定 | |
BETWEEN | 含有 | |
LIKE | 文字列パターンの一致 | |
< > | 等しくない(ブール値) | |
= | 右 | 等しい |
NOT | 右 | 否定 |
AND | 左 | 論理積 |
OR | 左 | 論理和 |