Skip to main content

REPLACE

Updates all fields in a resource (synonymous with a put operation).

See also:
[ StackQL Resource Hierarchy ] [ UPDATE ]


Syntax​

replaceStatement::=

REPLACEmultipartIdentifierSETfullFieldAssignment','fullFieldAssignmentWHEREexpression'AND''OR'expression';'

 
 

REPLACE [ /*+ AWAIT */ ] <multipartIdentifier>
SET field_name = value [, field_name = value ...]
[ WHERE condition ];

Examples​

Basic REPLACE statement​

Run a REPLACE statement to replace all of the topics on a GitHub repository.

-- 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 statement (blocking)​

Run a REPLACE statement to replace a Compute Engine firewall rule. This is a blocking (synchronous) invocation.

-- 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';

REPLACE statement with JSON functions​

Run a REPLACE statement whose value is built with JSON functions. A function that reads no columns is evaluated before the request is sent. A SET value cannot read the row being replaced, so to change part of an existing value, read it with a SELECT first and set the modified value.

-- 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';