Database Reference
In-Depth Information
This will remove all instances of the string 'carol' from the list. To remove an element
from the list by index, we use a special form of the DELETE statement:
DELETE "shared_by"[0]
FROM "user_status_updates"
WHERE "username" = 'alice'
AND "id" = 76e7a4d0-e796-11e3-90ce-5f98e903bf02;
Recall from the previous chapter that we can remove data from individual columns in a
row by specifying the column names directly after the DELETE keyword; in similar fash-
ion, we can remove data from individual indexes in a list.
Let's check the contents of the list to see the effects of our deletions:
What we've got left is a one-element list. The first deletion, by value, removed carol as
the last element; the second deletion, by index, removed david as the first element. Note
that, in both cases, the element in question was completely removed from the list, making
the list one element shorter.
Note
Like writing an element at a specific index, both approaches to remove data from a list re-
quire a scan of the list's contents before updating them. Removal of elements from lists is
thus slower than other collection manipulation operations, and should be avoided in
performance-sensitive code paths.
Search WWH ::




Custom Search