PostgreSQL – How to Combine Two Columns into One

postgresqlupdate

I have a table in PostgreSQL 11 with two varchar columns like this:

 A | B  
---+---
 m | n 
 x | y 

Now I want to add a column C which should contain the contents of A and B (concat(A, B)):

 A | B | C 
---+---+---
 m | n | mn
 x | y | xy

After that I want to drop A and B so that I effectively replace the two original columns.

How can I set the value of C to the concatenated values of A and B?

Best Answer

You seem to have already the solution yourself:

UPDATE thetable SET c = CONCAT(a, b)