Re: [sqlite] Inserting the same column multiple times

2019-04-14 Thread Shawn Wagner
On Sun, Apr 14, 2019 at 1:16 AM Luuk  wrote:

>
>
> Because, i do think, that it would never be possible to specify more
> than the number of columns in an insert statement?
>
>
The original issue was with some java/android sqlite binding that has a
method that builds an insert statement on the fly given lists of column
names and corresponding values being passed ones that had duplicates. It
might not be something any normal person does with a hand-written
statement, but automatically generated ones (combined with someone making
silly mistakes) are a different story.
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Inserting the same column multiple times

2019-04-14 Thread Luuk


On 14-4-2019 09:36, Shawn Wagner wrote:

Discovered this tonight answering a question on stack overflow:

sqlite> create table foo(a, b);
sqlite> insert into foo(a,b,a,b) values(1,2,3,4);
sqlite> select * from foo;
a   b
--  --
1   2

Inserting a column multiple times only uses the first corresponding value.
I don't see this documented anywhere.

By contract, a single UPDATE of the same column multiple times uses the
last one and ignores the rest:

sqlite> update foo set a=3, a=4;
sqlite> select * from foo;
a   b
--  --
4   2

And that is documented.

The inconsistency is annoying, but changing how either one works will
doubtless break somebody's code. Maybe clarify INSERT's behavior in its
documentation? Logging a warning in the case of a column being used
multiple times might be nice too.


An error like this one should do:

sqlite> insert into foo values(1,2,3,4);
Error: table foo has 2 columns but 4 values were supplied

Because, i do think, that it would never be possible to specify more 
than the number of columns in an insert statement?



MS-SQL has this:

create table foo(a int, b int);

insert into foo(a,b,a,b) values(1,2,3,4);

Msg 264, Level 16, State 1, Line 3
The column name 'a' is specified more than once in the SET clause or 
column list of an INSERT. A column cannot be assigned more than one 
value in the same clause. Modify the clause to make sure that a column 
is updated only once. If this statement updates or inserts columns into 
a view, column aliasing can conceal the duplication in your code.

Msg 264, Level 16, State 1, Line 3
The column name 'b' is specified more than once in the SET clause or 
column list of an INSERT. A column cannot be assigned more than one 
value in the same clause. Modify the clause to make sure that a column 
is updated only once. If this statement updates or inserts columns into 
a view, column aliasing can conceal the duplication in your code.



___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] Inserting the same column multiple times

2019-04-14 Thread Shawn Wagner
Discovered this tonight answering a question on stack overflow:

sqlite> create table foo(a, b);
sqlite> insert into foo(a,b,a,b) values(1,2,3,4);
sqlite> select * from foo;
a   b
--  --
1   2

Inserting a column multiple times only uses the first corresponding value.
I don't see this documented anywhere.

By contract, a single UPDATE of the same column multiple times uses the
last one and ignores the rest:

sqlite> update foo set a=3, a=4;
sqlite> select * from foo;
a   b
--  --
4   2

And that is documented.

The inconsistency is annoying, but changing how either one works will
doubtless break somebody's code. Maybe clarify INSERT's behavior in its
documentation? Logging a warning in the case of a column being used
multiple times might be nice too.
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users