Hi all,

I've been surprised that the following syntax doesn't work and returns 
"3 values for 4 columns" diagnose message.  I'm just asking by curiosity.

INSERT INTO t (a, b, c, d) VALUES ('aa', 'bb', (SELECT c, d FROM t 
WHERE <cond>));
     with <cond> guaranteed to select exactly one row.

I thought (probably naively) that the SELECT would be considered 
returning _two_ values.
If I read the SQLite syntax diagrams well, it should work.

In such case, is there a less pedestrian way to achieve the result than

INSERT INTO t (a, b, c, d)
   VALUES ('aa',
           'bb',
           (SELECT c FROM t WHERE <cond>),
           (SELECT d FROM t WHERE <cond>));

I know that such dupplication of fields is not the best design, but in 
the occurence, this small (100-200 rows) table only sees few inserts a 
year but heavy lookup.  I tend to make the lookup simpler.



_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to