Update Data in Postgres

Brett Cassette
InstructorBrett Cassette
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 5 years ago

Data changes. In some applications, it changes all the time! In this lesson we’ll learn how to update a single record or many at once.

[00:00] Now let's update our data. Let's say we're going to update our movies. We're going to set the count stars equal to one. Let's also select all from movies after that. We'll see every single movie got updated where its count stars are now one because we didn't limit this in any way. If we want to, we can use the where clause here.

[00:27] Let's say the name is "Kill Bill." I'm sure people were sad that I rated that solely before. Let's give it a five star. Name doesn't exist. That's a mistake I made here. Let's say where title equals Kill Bill.

[00:41] It's important to notice that we did in fact get this error. Title is Kill Bill. We have five stars now, that limited to just one movie and before we limit it to multiple movies or all of the movies. We can prove that we can limit to a subset of the movies here but more than one.

[01:01] Where the count stars is one, let's give this a three maybe. We see "Funny People" and "Blazing Saddles" now have three stars. Obviously, we can use any field here. If we want it to say where the release date is greater than, we keep using 1975, so this will be everything except Blazing Saddles.

[01:25] We'll set the count stars equal to zero. Pretty simple. That's a basic update. Remember we're always limiting to the where clause. Something that's helpful before you actually run an update is to look at what that's going to be. If we write this as a select statement, we can see which movies we're going to update before we actually issue the update command.

egghead
egghead
~ 6 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today