Copy fields from one column into another column with pgadmin 4 and sql?

1

I'm new to Postgresql and using pgadmin 4 on a mac. I have a table that has international and national addresses recorded in 4 columns for international, and four for national (country, state, city, zip). I want to combine international data with the national data so that all addresses data is in the same columns. by copying all international postal codes into the US zip code column. I tried the following SQL statement and a few others with no success.

UPDATE data_table
SET intl_postal_code = usa_zip 
WHERE usa_zip IS NULL

nothing happens with the above approach. Other variations resulted in some data copying but many rows were deleted.

I also tried using concat:

SELECT concat(usa_zip, intl_postal_code);

This also did not work, an error was returned saying the columns don't exist though they do.

seichner

Posted 2019-06-24T00:34:01.100

Reputation: 11

Answers

0

It looks like you've flipped the columns in the update statement. If you want to update the US zip column, it should be on the left hand side of the assignment operator:

UPDATE data_table SET usa_zip = intl_postal_code WHERE usa_zip IS NULL

Mureinik

Posted 2019-06-24T00:34:01.100

Reputation: 3 521