U
U
Urbansamurai2021-10-12 17:10:13
PostgreSQL
Urbansamurai, 2021-10-12 17:10:13

How to insert into the new json value, the value of another column in an UPDATE query?

Can you please tell me how to correctly specify subquery.email in this request?

UPDATE group_settings 
SET group_recepients='{"email": subquery.email, "telegram_token": "", "telegram_user_id":""}'
FROM (SELECT id, email from users) AS subquery WHERE group_settings.user_id = subquery.id;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2021-10-12
@Urbansamurai

Something like this

UPDATE group_settings 
SET group_recepients = jsonb_build_object('email', subquery.email, 'telegram_token', '', 'telegram_user_id', '')
FROM (SELECT id, email from users) AS subquery WHERE group_settings.user_id = subquery.id;

jsonb_build_object

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question