Re: psql generate insert command based on select

Поиск
Список
Период
Сортировка
От vibhor.kumar@enterprisedb.com
Тема Re: psql generate insert command based on select
Дата
Msg-id BC515A6E-63AF-4479-8BAF-FA6DF5B4F6B8@enterprisedb.com
обсуждение исходный текст
Ответ на psql generate insert command based on select  ("Leonardo M. Ramé" <l.rame@griensu.com>)
Ответы Re: psql generate insert command based on select  ("Leonardo M. Ramé" <l.rame@griensu.com>)
Список pgsql-general
On Oct 10, 2014, at 1:27 PM, Leonardo M. Ramé <l.rame@griensu.com> wrote:

> Hi, today I needed to re-create certain records deleted from a mysql database, so I restored an old backup, opened a
terminaland logged in to the old database using the "mysql" command line utility, then opened a new terminal with mysql
connectedto the production database. Then did a "select * from table where id=xxx \G;" to display a record, then, on
theother terminal I had to write "insert into table(field1, field2,...,fieldN) values(...);" for each record. 
>
> While doing that I tought of a neat feature that psql could provide, that is something like "\insert for select *
fromtable where id=xxx;" this should create the insert command for the requested query. 

You can do something like given below:
CREATE TABLE temp_generate_inserts AS SELECT * FROM table id=xx
Then use pg_dump --column-inserts  -t temp_generate_inserts db1|psql db2
and later you can drop temp_generate_inserts table.

With this you can also explore dblink_build_sql_insert function which comes with dblink module:
http://www.postgresql.org/docs/9.3/interactive/contrib-dblink-build-sql-insert.html

Thanks & Regards,
Vibhor Kumar
(EDB) EnterpriseDB Corporation
The Postgres Database Company
Blog:http://vibhork.blogspot.com



В списке pgsql-general по дате отправления:

Предыдущее
От: Connor Wolf
Дата:
Сообщение: Re: Understanding and implementing a GiST Index
Следующее
От: "Leonardo M. Ramé"
Дата:
Сообщение: Re: psql generate insert command based on select