The syntax "WITH p AS (SELECT 1) INSERT INTO t(x) SELECT * FROM p;" throws
the same exception: "[2015-10-13 08:20:22] [1] [SQLITE_ERROR] SQL error or
missing database (near ")": syntax error)"



On Tue, Oct 13, 2015 at 8:17 AM, Clemens Ladisch <clemens at ladisch.de> wrote:

> Don V Nielsen wrote:
> > I'm struggling to implement an INSERT statement that get's is values
> from a
> > CTE.
> >
> > insert into vo_crrt_pieces (recid)
> > values (
> >   with
> >   pkg_controls AS (
> >     SELECT * FROM d_pkg WHERE pkg_level = 'CRD'
> >   )
> >   -- select pieces that meeting pkg and pkg_level minimums
> >   , min_pkgs_met AS (
> >   ...
> >   )
> >   SELECT recid
> >   FROM addresses [c]
> >   JOIN min_pkgs_met [a] ON a.zip = c.zip AND a.crrt = a.crrt
> > )
>
> Without the database schema, this is impossible to test.
>
> A CTE is allowed where a SELECT is allowed, so you have to use the
> SELECT form of the INSERT statement:
>
>  CREATE TABLE t(x);
>  INSERT INTO t(x) SELECT 1;
>
>  INSERT INTO t(x) WITH p AS (SELECT 1) SELECT * FROM p; -- or:
>  WITH p AS (SELECT 1) INSERT INTO t(x) SELECT * FROM p;
>
>
> Regards,
> Clemens
> _______________________________________________
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>

Reply via email to