Re: [sqlite] I want to use CREATE TABLE ... AS SELECT ... - but what if the SELECT returns no rows?

2014-07-10 Thread Tim Streater
On 10 Jul 2014 at 14:17, Mark Lawrence wrote: > On Thu Jul 10, 2014 at 01:52:00PM +0100, Tim Streater wrote: >> >> What I'm actually doing is moving/copying a row from one database to >> another, where the two databases have identical schemas. >> ... >> >> So there are two copy

Re: [sqlite] I want to use CREATE TABLE ... AS SELECT ... - but what if the SELECT returns no rows?

2014-07-10 Thread Mark Lawrence
On Thu Jul 10, 2014 at 01:52:00PM +0100, Tim Streater wrote: > > What I'm actually doing is moving/copying a row from one database to > another, where the two databases have identical schemas. > ... > > So there are two copy steps. What I'd like to do is: > > ... > > but unfortunately there

Re: [sqlite] I want to use CREATE TABLE ... AS SELECT ... - but what if the SELECT returns no rows?

2014-07-10 Thread Tim Streater
On 10 Jul 2014 at 12:45, Simon Slavin wrote: > On 10 Jul 2014, at 11:47am, Clemens Ladisch wrote: > >> This is indeed misleading. The result set actually has columns and >> column names even when there are now rows in it, so this is guaranteed >> to

Re: [sqlite] I want to use CREATE TABLE ... AS SELECT ... - but what if the SELECT returns no rows?

2014-07-10 Thread Simon Slavin
On 10 Jul 2014, at 11:47am, Clemens Ladisch wrote: > This is indeed misleading. The result set actually has columns and > column names even when there are now rows in it, so this is guaranteed > to work even for empty result sets. However, all is not as you might expect:

Re: [sqlite] I want to use CREATE TABLE ... AS SELECT ... - but what if the SELECT returns no rows?

2014-07-10 Thread Clemens Ladisch
Tim Streater wrote: > I have a handy SELECT available, but I don't want to actually insert > a row at that time. Testing with the shell, the following appears to > work: > > attach database ':memory:' as mem; > create table mem.messages as select * from main.messages limit 0; > > and I get a

Re: [sqlite] I want to use CREATE TABLE ... AS SELECT ... - but what if the SELECT returns no rows?

2014-07-10 Thread Tim Streater
On 10 Jul 2014 at 11:20, Dan Kennedy wrote: > On 07/10/2014 04:45 PM, Tim Streater wrote: >> I have just noticed this syntax which will simplify some table creation for >> me. However in some instances where I want to use it, I have a handy SELECT >> available, but I don't

Re: [sqlite] I want to use CREATE TABLE ... AS SELECT ... - but what if the SELECT returns no rows?

2014-07-10 Thread Dan Kennedy
On 07/10/2014 04:45 PM, Tim Streater wrote: I have just noticed this syntax which will simplify some table creation for me. However in some instances where I want to use it, I have a handy SELECT available, but I don't want to actually insert a row at that time. Testing with the shell, the

[sqlite] I want to use CREATE TABLE ... AS SELECT ... - but what if the SELECT returns no rows?

2014-07-10 Thread Tim Streater
I have just noticed this syntax which will simplify some table creation for me. However in some instances where I want to use it, I have a handy SELECT available, but I don't want to actually insert a row at that time. Testing with the shell, the following appears to work: attach database