翻訳ページ
このページは AI の支援を受けて英語から翻訳されています。内容が異なる場合は英語版が正となります。
REPLACE
リソースのすべてのフィールドを更新します(put 操作と同義)。
関連項目:
[ StackQL リソース階層 ] [ UPDATE ]
構文
replaceStatement::=
REPLACE [ /*+ AWAIT */ ] <multipartIdentifier>
SET field_name = value [, field_name = value ...]
[ WHERE condition ];
例
基本的な REPLACE 文
GitHub リポジトリのトピックをすべて置換する REPLACE 文を実行します。
-- Replace all of the topics on a GitHub repository
REPLACE github.repos.topics
SET data__names = '["sql", "cloud-infrastructure"]'
WHERE owner = 'my-org'
AND repo = 'my-repo';
REPLACE 文(ブロッキング)
Compute Engine のファイアウォールルールを置換する REPLACE 文を実行します。これはブロッキング(同期)呼び出しです。
-- Synchronous update of a google firewall
REPLACE /*+ AWAIT */ google.compute.firewalls
SET
data__name = 'test-fw',
data__network = 'https://www.googleapis.com/compute/v1/projects/stackql-demo/global/networks/my-vpc',
data__direction = 'INGRESS',
data__sourceRanges = '["0.0.0.0/0"]',
data__allowed = '[{"IPProtocol": "tcp", "ports": ["22"]}, {"IPProtocol": "tcp", "ports": ["6443"]},{"IPProtocol": "icmp"}]'
WHERE firewall = 'test-fw'
AND project = 'stackql-demo';
JSON 関数を使用する REPLACE 文
値を JSON 関数で組み立てる REPLACE 文を実行します。列を読み取らない関数は、リクエストの送信前に評価されます。SET の値は置換対象の行を読み取れません。そのため、既存の値の一部を変更するには、まず SELECT で値を読み取り、変更後の値を設定します。
-- Replace the topics on a GitHub repository with a list built by json_array
REPLACE github.repos.topics
SET data__names = json_array('sql', 'cloud-infrastructure', 'infrastructure-as-code')
WHERE owner = 'my-org'
AND repo = 'my-repo';