翻譯頁面
本頁面由英文在 AI 協助下翻譯而成。若兩者有出入,請以英文版本為準。
REPLACE
更新資源中的所有欄位(等同於 put 作業)。
另請參閱:
[ StackQL 資源階層 ] [ UPDATE ]
語法
replaceStatement::=
REPLACE [ /*+ AWAIT */ ] <multipartIdentifier>
SET field_name = value [, field_name = value ...]
[ WHERE condition ];
範例
基本 REPLACE 陳述式
執行 REPLACE 陳述式,取代 GitHub 存放庫上的所有主題。
-- 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 陳述式(封鎖式)
執行 REPLACE 陳述式,取代 Compute Engine 防火牆規則。這是封鎖式(同步)叫用。
-- 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';