This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Update Data in Postgres

    Brett CassetteBrett Cassette

    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.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    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.

    Discuss

    Discuss