翻译页面
本页面由 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';