Updating data​

The types used in these queries are defined here.

Flag all reviews to a specific movie:

  1. update Review
  2. filter
  3. Review.movie.title = 'Dune'
  4. and
  5. Review.movie.director.last_name = 'Villeneuve'
  6. set {
  7. flag := True
  8. }

Add an actor with a specific list_order link property to a movie:

  1. update Movie
  2. filter
  3. .title = 'Dune'
  4. and
  5. .directors.last_name = 'Villeneuve'
  6. set {
  7. actors := (
  8. insert Person {
  9. first_name := 'Timothee',
  10. last_name := 'Chalamet',
  11. image := 'tchalamet.jpg',
  12. @list_order := 1,
  13. }
  14. )
  15. }

Using a for query to set a specific list_order link property for the actors list:

  1. update Movie
  2. filter
  3. .title = 'Dune'
  4. and
  5. .directors.last_name = 'Villeneuve'
  6. set {
  7. actors := (
  8. for x in {
  9. ('Timothee Chalamet', 1),
  10. ('Zendaya', 2),
  11. ('Rebecca Ferguson', 3),
  12. ('Jason Momoa', 4),
  13. }
  14. union (
  15. select Person {@list_order := x.1}
  16. filter .full_name = x.0
  17. )
  18. )
  19. }

Updating a multi link by adding one more item:

  1. update Movie
  2. filter
  3. .title = 'Dune'
  4. and
  5. .directors.last_name = 'Villeneuve'
  6. set {
  7. actors += (
  8. insert Person {
  9. first_name := 'Dave',
  10. last_name := 'Bautista',
  11. image := 'dbautista.jpg',
  12. }
  13. )
  14. }

Updating a multi link by removing an item:

  1. update Movie
  2. filter
  3. .title = 'Dune'
  4. and
  5. .directors.last_name = 'Villeneuve'
  6. set {
  7. actors -= (
  8. select Person
  9. filter
  10. .full_name = 'Jason Momoa'
  11. )
  12. }

Update the list_order link property for a specific link:

  1. update Movie
  2. filter
  3. .title = 'Dune'
  4. and
  5. .directors.last_name = 'Villeneuve'
  6. set {
  7. # The += operator will allow updating only the
  8. # specified actor link.
  9. actors += (
  10. select Person {
  11. @list_order := 5,
  12. }
  13. filter .full_name = 'Jason Momoa'
  14. )
  15. }

See also

EdgeQL > Update

Reference > Commands > Update