Perform Upserts Without Schemas
Learn how to perform upserts without schemas.
The genres
table
To practice upserts, let’s return to the genres
table. This table is fairly small and has just two fields:
name
wiki_tag
We can use the wiki_tag
to create a link to the Wikipedia article to learn more about the genre.
We added a unique index on the ‘name’ column when we set up the table in our music_db
database. This ensures that we don’t accidentally set up two genres with the same name—we wouldn’t want to create two records for “jazz.” We can use this unique index to help us with our upserts.
Create a new record, twice
First, let’s use insert_all
to create a new record for the “ska”
genre.
Get hands-on with 1400+ tech skills courses.