https://github.com/schibsted/copyfield
Update fields in a PostgreSQL database with values from another column
https://github.com/schibsted/copyfield
go postgresql utility
Last synced: 2 months ago
JSON representation
Update fields in a PostgreSQL database with values from another column
- Host: GitHub
- URL: https://github.com/schibsted/copyfield
- Owner: schibsted
- License: apache-2.0
- Created: 2023-04-07T15:42:27.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-07T17:02:18.000Z (about 3 years ago)
- Last Synced: 2025-03-08T21:39:55.789Z (over 1 year ago)
- Topics: go, postgresql, utility
- Language: Go
- Homepage:
- Size: 88.9 KB
- Stars: 2
- Watchers: 7
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Copyfield [](https://github.com/schibsted/copyfield/actions/workflows/build.yml)
Copy a value from one field in a table, to another field in the same table, in a PostgreSQL database.
The entire process can be stopped with `ctrl-c` and resumed by running the command again, since the progress is stored in `progress.txt`.
### Installation
Requires Go >= 1.17:
go install github.com/schibsted/copyfield@latest
### Example use
NOTE: Replace `PASSWORD` with your password, for all commands below.
Copy values from the "transactional" field to the "shipping" field:
copyfield -dbname feedback -host 127.0.0.1 -port 5433 -password PASSWORD -table trade -src transactional -dst shipping -user feedback_user -id trade_id
Copy values from the "transactional" field to the "shipping" field, and create the "shipping" column first if it does not exist:
copyfield -dbname feedback -host 127.0.0.1 -port 5433 -password PASSWORD -table trade -src transactional -dst shipping -user feedback_user -id trade_id -newcol "BOOLEAN DEFAULT FALSE NOT NULL"
Examine values:
psql -h localhost -p 5433 --username=feedback_user feedback
For servers that are not running on localhost, adding `-sslmode=1` is most likely needed.
### Reset the counter and remove a column
Remove the file with the overview of the current progress:
rm progress.txt
Also drop the column, if needed (replace `` and `` with your own):
ALTER TABLE DROP COLUMN ;
### Progress
The progress is stored as a list of table indices in `index.txt`. The file is written to (flushed) every time a row in the database has been modified.
### General info
* Author: Alexander F. Rødseth
* License: [Apache 2](LICENSE)
* Version: 1.0.1
### The contents of the NOTICE file
(Required, per company policy).
```
################################################################################
# #
# Copyfield #
# #
# Copyright 2023 Schibsted #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# #
################################################################################
```