<productname>PostgreSQL</productname> includes one merge support function
that may be used in the <literal>RETURNING</literal> list of a
<xref linkend="sql-merge"/> command to identify the action taken for each
row; see <xref linkend="functions-merge-support-table"/>.
PostgreSQLには、各行に対して行われたアクションを識別するためにMERGEコマンドのRETURNINGリストで使用されるマージサポート関数が1つ含まれています。
詳細は表 9.68を参照してください。
表9.68 マージサポート関数
Function 関数 Description 説明 |
|---|
|
Returns the merge action command executed for the current row. This
will be <literal>'INSERT'</literal>, <literal>'UPDATE'</literal>, or
<literal>'DELETE'</literal>.
現在の行に対して実行されたマージアクションコマンドを返します。
これは |
Example: 例:
MERGE INTO products p
USING stock s ON p.product_id = s.product_id
WHEN MATCHED AND s.quantity > 0 THEN
UPDATE SET in_stock = true, quantity = s.quantity
WHEN MATCHED THEN
UPDATE SET in_stock = false, quantity = 0
WHEN NOT MATCHED THEN
INSERT (product_id, in_stock, quantity)
VALUES (s.product_id, true, s.quantity)
RETURNING merge_action(), p.*;
merge_action | product_id | in_stock | quantity
--------------+------------+----------+----------
UPDATE | 1001 | t | 50
UPDATE | 1002 | f | 0
INSERT | 1003 | t | 10
Note that this function can only be used in the <literal>RETURNING</literal>
list of a <command>MERGE</command> command. It is an error to use it in any
other part of a query.
この関数はMERGEコマンドのRETURNINGリストでのみ使用可能であることに注意してください。
問い合わせの他の部分で使用するとエラーになります。