It sounds like it should be easy but I can't see any reasonable way of doing it. How do you make a copy of a table in an sqlite3 database?
I can copy the database, that's trivial, but I want to duplicate a *table* within a database and that seems distinctly un-trivial.
Any ideas/suggestions anyone?
On Tue, Mar 09, 2010 at 09:46:31PM +0000, Chris G wrote:
It sounds like it should be easy but I can't see any reasonable way of doing it. How do you make a copy of a table in an sqlite3 database?
I can copy the database, that's trivial, but I want to duplicate a *table* within a database and that seems distinctly un-trivial.
INSERT INTO newtable SELECT * FROM oldtable;
assuming newtable and oldtable share the same schema?
J.
On Tue, Mar 09, 2010 at 09:51:55PM +0000, Jonathan McDowell wrote:
On Tue, Mar 09, 2010 at 09:46:31PM +0000, Chris G wrote:
It sounds like it should be easy but I can't see any reasonable way of doing it. How do you make a copy of a table in an sqlite3 database?
I can copy the database, that's trivial, but I want to duplicate a *table* within a database and that seems distinctly un-trivial.
INSERT INTO newtable SELECT * FROM oldtable;
assuming newtable and oldtable share the same schema?
I need to CREATE newtable first to be able to do that. Is there a similarly easy way to create newtable with the same schema as oldtable?
On Tue, Mar 09, 2010 at 09:58:42PM +0000, Chris G wrote:
On Tue, Mar 09, 2010 at 09:51:55PM +0000, Jonathan McDowell wrote:
On Tue, Mar 09, 2010 at 09:46:31PM +0000, Chris G wrote:
It sounds like it should be easy but I can't see any reasonable way of doing it. How do you make a copy of a table in an sqlite3 database?
I can copy the database, that's trivial, but I want to duplicate a *table* within a database and that seems distinctly un-trivial.
INSERT INTO newtable SELECT * FROM oldtable;
assuming newtable and oldtable share the same schema?
I need to CREATE newtable first to be able to do that. Is there a similarly easy way to create newtable with the same schema as oldtable?
CREATE TABLE newtable AS SELECT * FROM oldtable;
J.
On Tue, Mar 09, 2010 at 10:06:33PM +0000, Jonathan Google McDowell wrote:
On Tue, Mar 09, 2010 at 09:58:42PM +0000, Chris G wrote:
On Tue, Mar 09, 2010 at 09:51:55PM +0000, Jonathan McDowell wrote:
On Tue, Mar 09, 2010 at 09:46:31PM +0000, Chris G wrote:
It sounds like it should be easy but I can't see any reasonable way of doing it. How do you make a copy of a table in an sqlite3 database?
I can copy the database, that's trivial, but I want to duplicate a *table* within a database and that seems distinctly un-trivial.
INSERT INTO newtable SELECT * FROM oldtable;
assuming newtable and oldtable share the same schema?
I need to CREATE newtable first to be able to do that. Is there a similarly easy way to create newtable with the same schema as oldtable?
CREATE TABLE newtable AS SELECT * FROM oldtable;
Brilliant, thanks, I didn't realise you could CREATE TABLE like this, I know about INSERT INTO newtable SELECT *.
That makes it very simple.