Database Reference
In-Depth Information
UPDATE "user_status_updates"
SET "shared_by"[1] = 'robert'
WHERE "username" = 'alice'
AND "id" = 76e7a4d0-e796-11e3-90ce-5f98e903bf02;
Like array indexes in most programming languages, the index for list element assignment
is zero, meaning that in the preceding query we are setting the second element of the list.
List element assignment must reference an index that is within the list's current size. For
instance, if we try to assign the fourth element in our current three-element list:
UPDATE "user_status_updates"
SET "shared_by"[3] = 'maurice'
WHERE "username" = 'alice'
AND "id" = 76e7a4d0-e796-11e3-90ce-5f98e903bf02;
We'll get an out of bounds error:
Note
Replacing the value at a given index requires a scan of the list's contents internally, unlike
prepending and appending that can be performed without reading any data. This scan
makes replacement more expensive than prepending or appending. However, since the ac-
tual write is still performed discretely, the operation is still resilient to concurrent updates.
Removing elements from the list
Elements can be removed from a list either by value or by index. Removal by value is
identical to set removal, other than the literal format:
UPDATE "user_status_updates"
SET "shared_by" = "shared_by" - ['carol']
WHERE "username" = 'alice'
AND "id" = 76e7a4d0-e796-11e3-90ce-5f98e903bf02;
Search WWH ::




Custom Search