update res_user set date_of_birth= '1991-07-30' where name = 'USER1';
This work but can update just one row.
In my case I want to update multiple rows with different data in the same query so I wrote that, it doesn't work unfortunately.
Query:
update res_user as ru set
date_of_birth = n.date_of_birth
from (values
('1991-07-30','User1'),
('1980-06-30','User2'),
('1975-02-12','User3'),
) as n(date_of_birth, name)
where n.name = ru.name;
Result:
ERROR: column "date_of_birth" is of type date but expression is of
type text
LINE 2: date_of_birth = n.date_of_birth
^
HINT: You will need to rewrite or cast the expression.
You need to cast:
update res_user as ru set
date_of_birth = n.date_of_birth
from (values
('1991-07-30'::date,'User1'),
('1980-06-30'::date,'User2'),
('1975-02-12'::date,'User3'),
) as n(date_of_birth, name)
where n.name = ru.name;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With