Hi SImon,
Sorry if my replies seem a little disjointed - I get a daily digest of the
list so I don't see any responses to my posts until the next day.

Anyway, turns out this solution doesnt work - the INSERT fails because
there are two columns in t3 but only 1 column named in the SELECT.  The
solution is per Michael's later reply which is :

INSERT into t3 (Col1) SELECT Col1 FROM t2;

Thanks to everyone for the solution.

Pete

On Thu, Apr 5, 2012 at 9:00 AM, <sqlite-users-requ...@sqlite.org> wrote:

> Message: 10
> Date: Thu, 5 Apr 2012 01:38:57 +0100
> From: Simon Slavin <slav...@bigfraud.org>
> To: General Discussion of SQLite Database <sqlite-users@sqlite.org>
> Subject: Re: [sqlite] INSERT INTO with SELECT
> Message-ID: <bb6e260a-182b-4fac-a95d-fb9b115cd...@bigfraud.org>
> Content-Type: text/plain; charset=us-ascii
>
>
> On 5 Apr 2012, at 1:36am, Pete <p...@mollysrevenge.com> wrote:
>
> > Here's my test:
> >
> > CREATE TABLE t2 (Col1 text,Col2 text);
> > insert into t2 (Col1) values('xxx');
> > select * from t2
> > xxx|
> >
> > CREATE TABLE t3 (Col1 text,Col2 text default 'abc');
> > insert into t3 SELECT * FROM t2;
> > select * from t3;
> > xxx|
> >
> > Why does t3.Col2 not have it's default value of 'abc'?
>
> Because you fed it a value for the second column: NULL.  If you want the
> second column to have a default value you might find that
>
> insert into t3 SELECT Col1 FROM t2;
>
> works.
>
> Simon.
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to