April 2017
Beginner to intermediate
360 pages
9h 35m
English
In our previous example, we directly set the initial value of the starred_by_users column in the status update row, and only then did we perform discrete additions and removals. What happens if we try to add a value to a set that doesn't exist? Let's try it on a different status update, one that has no value in the starred_by_users column:
UPDATE "user_status_updates" SET "starred_by_users" = "starred_by_users" + {'alice'} WHERE username = 'bob' AND id = 97719c50-e797-11e3-90ce-5f98e903bf02;
On running the query, we don't get any error message, which is a promising sign. Let's have a look at the contents of that row now:
As it turns out, we now have a one-element set containing the alice username. Adding data to ...
Read now
Unlock full access