/* Code Comments */

Copying Data From One Column To Another With SQL

March 08, 2019

If you need to copy all data from one column to another column in SQL, use the UPDATE method.

If it’s a simple copy for copy, without conditionals, across tables, etc., the query is simply:

UPDATE `table_name` SET
	`destination_column` = `source_column`

The full set of options :

[ WITH [ RECURSIVE ] with_query [,] ]
UPDATE [ ONLY ] table_name [ * ] [ [ AS ] alias ]
    SET { column_name = { expression | DEFAULT } |
          ( column_name [,] ) = [ ROW ] ( { expression | DEFAULT } [,] ) |
          ( column_name [,] ) = ( sub-SELECT )
        } [,]
    [ FROM from_list ]
    [ WHERE condition | WHERE CURRENT OF cursor_name ]
    [ RETURNING * | output_expression [ [ AS ] output_name ] [,] ]

Full documentation on UPDATE in Postgres for the current version (11), is here: PostgreSQL: Documentation: 11: UPDATE

For more discussions, see StackOverflow:

Turns out that at least in the simplest case, Postgres and MySQL are identical.


Stephen Weiss

Thanks for reading! My name's Stephen Weiss. I live in Chicago with my wife, Kate, and dog, Finn.
Click here to see the archives of my weeks in review and sign up yourself!