Fork me on GitHub
#sql
<
2021-09-06
>
finchharold14:09:36

Hi all, I have a table called portal and it is having a column called status_id.

seq_id | segment | exp 
-------------+--------+-----------
          20 |      1 |        -1
          25 |      1 |        -1
          23 |      1 |        -1
          22 |      1 |        -1
          19 |      1 |        -1
          26 |      1 |        -2
          21 |      1 |        -1
          24 |      1 |        -1
Now there is another table called info, and it is having a JSONB column called experience.
id | seg_id |        experience        
----+--------+--------------------
 20 |      1 | {"work": 0}
 25 |      1 | {"work": 0}
 23 |      1 | {"work": 0}
 22 |      1 | {"work": 0}
 19 |      1 | {"work": 0}
 26 |      1 | {"work": 0}
 21 |      1 | {"work": 0}
 24 |      1 | {"work": 0}
Here, I am trying to update the value of `work` inside experience by taking the values of exp based on the `seq_id = id` in one query I tried:
UPDATE info SET experience = '{"work": (portal.exp)}' FROM portal WHERE exp IS NOT NULL AND seq_id = info.id;

finchharold14:09:41

But it's not working

finchharold14:09:56

What am I missing?

V14:09:55

What SQL DBMS are you using?

valtteri18:09:36

You should update json fields with proper operations, such as jsonb_set

John Bradens19:09:21

Hi I'm a beginner to making web apps and I'm really interested in learning more about databases. I'd love to have more general knowledge & understanding of a broad range of DB topics. I've been googling lots of things, but I think a book might include interesting topics I wouldn't have thought to research. What beginner books/blogs/websites do you recommend?

seancorfield19:09:23

This might be a helpful read @bradj4333 https://mariadb.com/kb/en/introduction-to-relational-databases/ (it seems to cover a lot of the basics in bite-size chunks).

John Bradens19:09:58

@seancorfield thank you I'll look into that, sounds like just what i'm looking for!