2

I am new to PostgreSQL. Now I have a table containing several columns. There are two columns I'm dealing with: city and city_bak. city_bak is of type integer and stores data of cities. The city column is currently null and is of type integer[]. What I want to do is to copy data from city_bak into city. Like this:

[PREVIOUS]

 |  city  |  city_bak  |
 |        |    100     |
 |        |    700     |
 |        |    1800    |

[AFTER]

 |  city  |  city_bak  |
 | {100}  |    100     |
 | {700}  |    700     |
 | {1800} |    1800    |

Normally when the two columns are of the same data type, I'd use

UPDATE {table_name} SET city=city_bak

But now they are different. How can I copy data in this scenario? Thanks in advance.

1 Answer 1

2

Is this what you want?

UPDATE {table_name}
    SET city = ARRAY[city_bak];
Sign up to request clarification or add additional context in comments.

1 Comment

That's it! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.