Hello Brian,

you do not need a VALUE keyword in this case.

INSERT INTO "subscribers_new"
--    VALUES  <- remove this
    SELECT id, ip_address, added, 'aa:bb:cc:etc' from subscribers;

See the syntax diagram for the insert command: 
http://www.sqlite.org/lang_insert.html

Martin


Brian Zambrano schrieb:
> Can anyone explain to me why an insert with select statement isn't working?
> I know in my my example below I just have an extra column which I could have
> added, but my actual tables are a bit more complex and this below is just to
> demonstrate the problem.
>
> -- Original table
> CREATE TABLE "subscribers" (
>         "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
>         "ip_address" char(15) NOT NULL UNIQUE,
>         "added" integer NOT NULL
>     );
>
> -- New table
> CREATE TABLE "subscribers_new" (
>         "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
>         "ip_address" char(15) NOT NULL UNIQUE,
>         "added" integer NOT NULL,
>         "mac_address" char(32) NOT NULL
>     );
> SQL error: near ""mac_address"": syntax error
>
> -- insert a couple of rows into the original
> INSERT INTO "subscribers" VALUES (1, '1.2.3.4', 123456);
> INSERT INTO "subscribers" VALUES (2, '11.22.33.44', 1111111);
>
> -- Now try to insert into new table with select, and see failure
> INSERT INTO "subscribers_new"
>     VALUES
>     SELECT id, ip_address, added, 'aa:bb:cc:etc' from subscribers;
> SQL error: near "SELECT": syntax error
>
> -- Note, the select statement by itself works just fine:
>
> SELECT id, ip_address, added, 'aa:bb:cc:etc' from subscribers;
> id|ip_address|added|'aa:bb:cc:etc'
> 1|1.2.3.4|123456|aa:bb:cc:etc
> 2|11.22.33.44|1111111|aa:bb:cc:etc
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
>   
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to