From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
---|---|
To: | "Leonardo M(dot) Ramé" <l(dot)rame(at)griensu(dot)com>, PostgreSql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: psql generate insert command based on select |
Date: | 2014-10-10 17:37:55 |
Message-ID: | 54381973.3050200@aklaver.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 10/10/2014 10:27 AM, "Leonardo M. Ramé" wrote:
> Hi, today I needed to re-create certain records deleted from a mysql
> database, so I restored an old backup, opened a terminal and logged in
> to the old database using the "mysql" command line utility, then opened
> a new terminal with mysql connected to the production database. Then did
> a "select * from table where id=xxx \G;" to display a record, then, on
> the other 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 * from table where id=xxx;"
> this should create the insert command for the requested query.
>
> Is such a thing already present in psql?.
I may be missing something but:
http://www.postgresql.org/docs/9.3/interactive/sql-insert.html
INSERT INTO films SELECT * FROM tmp_films WHERE date_prod < '2004-05-07';
or are you thinking of something that takes a SELECT query and turns it
into a series of INSERT queries.
The only way I can of doing this is to use pg_dump -t some_table -a
--inserts or --column-inserts
>
> Regards,
>
--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Nick Barnes | 2014-10-10 17:41:40 | Re: FK check implementation |
Previous Message | Leonardo M. Ramé | 2014-10-10 17:27:52 | psql generate insert command based on select |