Database Reference
In-Depth Information
Reading and writing sets
Before getting into the more powerful operations we can perform on sets, let's start with the
basics. Rerunning the scenario we explored earlier, let's naïvely use the exact same ap-
proach as we did the first time to record bob 's status update. First, we'll read the value of
the set:
SELECT "starred_by_users"
FROM "user_status_updates"
WHERE "username" = 'alice'
AND "id" = 76e7a4d0-e796-11e3-90ce-5f98e903bf02;
Once again, we see that the value of the set is currently null :
This means that we can write a one-element set containing the text value bob to the
starred_by_users column in the status update:
UPDATE "user_status_updates"
SET "starred_by_users" = {'bob'}
WHERE "username" = 'alice'
AND "id" = 76e7a4d0-e796-11e3-90ce-5f98e903bf02;
This query introduces some new syntax, specifically the value we're writing to
starred_by_users . The value we specify is a set literal, which is simply a comma-de-
limited list of values surrounded by curly braces. Each collection type has its own literal
format.
Let's check the contents of the status update row to see the effect of our update:
Search WWH ::




Custom Search