I can see 4 approaches:
1. export that columns as .csv
and import from it on seccond DB
COPY (
SELECT language, title FROM cms_title WHERE language != 'en' AND title != 'Blog'
) TO '/path/to/csv/cms_title_dump.csv' WITH CSV HEADER DELIMITER ';';
put that .csv
in path accessible for destination server on that server perform importing:
COPY cms_title FROM '/path/to/csv/cms_title_dump.csv' DELIMITER ';' CSV;
or \copy to use the command in psql + db
2. dump it using pg_dump
and restore (pg_restore
) on seccond DB
dump:
pg_dump opencare -F c -h db_address -U db_user -p sb_port -t cms_title -f /path/to/dump/cms_title.dump;
restore:
pg_restore -h dest_db_address -U dest_db_user -p dest_dp_port -d db_name /path/to/dump/cms_title.dump;
In this case you must remember that pg_dump
performs dump of WHOLE table data. You can't choose subset of rows from table to dump. So this option is appropiate when doing table mirroring from ona DB to another.
3. use dblink
module for PostgreSQL to perform coss-database queries
4. generate INSERT
query and execute it on seccond server:
`SELECT
'INSERT INTO cms_title(language, title) VALUES '
|| string_agg( '(' || language || ', '|| title || ')', ',' )
|| ';'
FROM cms_title WHERE language != 'en' AND title != 'Blog';`