明示的なトランザクションの使用¶
明示的な トランザクション で SQL ステートメントを実行するには、 単一の HTTP リクエスト を使用して、トランザクション内の開始、終了、およびステートメントを指定する必要があります。例:
{ "statement": "begin transaction; insert into table2 (i) values (1); commit; select i from table1 order by i", ... "parameters": { "MULTI_STATEMENT_COUNT": "4" } ... }
リクエストで複数のステートメント を指定する場合と同様に、リクエストが正常に処理された場合、Snowflakeは statementHandles
フィールドを含むレスポンスを返します。フィールドは、リクエスト内(BEGIN TRANSACTION および COMMIT ステートメントを含む)にあるステートメントのハンドルの配列に設定されます。
HTTP/1.1 200 OK Content-Type: application/json { "resultSetMetaData" : { "numRows" : 1, "format" : "jsonv2", "rowType" : [ { "name" : "multiple statement execution", "database" : "", "schema" : "", "table" : "", "type" : "text", "byteLength" : 16777216, "scale" : null, "precision" : null, "nullable" : false, "collation" : null, "length" : 16777216 } ] }, "data" : [ [ "Multiple statements executed successfully." ] ], "code" : "090001", "statementHandles" : [ "019d6ed0-0502-3101-0000-096d00421082", "019d6ed0-0502-3101-0000-096d00421086", "019d6ed0-0502-3101-0000-096d0042108a", "019d6ed0-0502-3101-0000-096d0042108e" ], "statementStatusUrl" : "/api/v2/statements/019d6ed0-0502-3101-0000-096d0042107e?requestId=066920fa-e589-43c6-8cca-9dcb2d4be978", "sqlState" : "00000", "statementHandle" : "019d6ed0-0502-3101-0000-096d0042107e", "message" : "Statement executed successfully.", "createdOn" : 1625684162876 }
statementHandles
フィールドのハンドルは、リクエストのステートメントに対応しています。この例で、ステートメントとそれに対応するハンドルは次のとおりです。
BEGIN TRANSACTION (
019d6ed0-0502-3101-0000-096d00421082
)INSERT (
019d6ed0-0502-3101-0000-096d00421086
)COMMIT (
019d6ed0-0502-3101-0000-096d0042108a
)SELECT (
019d6ed0-0502-3101-0000-096d0042108e
)
これらのハンドルを使用して、 各ステートメントのステータスを確認 できます。