[sqlite] bug when columns are missing in embedded subselect

2015-12-16 Thread Hick Gunter
This has been discussed several times on the list. SQLite (and all other 
databases) try very hard to resolve the names you refer to in your query and 
will search all the tables you mention to find *unqualified* references. They 
give up if they do not find exactly one definition.

Try " delete from inflight where inflight.fp in (select flightplans.fp from 
flightplans);

-Urspr?ngliche Nachricht-
Von: sqlite-users-bounces at mailinglists.sqlite.org 
[mailto:sqlite-users-bounces at mailinglists.sqlite.org] Im Auftrag von Karl 
Lehenbauer
Gesendet: Dienstag, 15. Dezember 2015 20:50
An: sqlite-users at mailinglists.sqlite.org
Betreff: [sqlite] bug when columns are missing in embedded subselect

Consider the following table definitions:


DROP TABLE IF EXISTS flightplans;


CREATE TABLE flightplans (

id text NOT NULL,

ident text,

recvd integer,

orig text,

dest text,

PRIMARY KEY (id)

);



DROP TABLE IF EXISTS inflight;


CREATE TABLE inflight (

fp text,

ident text,

alt integer,

clock integer NOT NULL DEFAULT 0,

gs integer,

heading integer,

lat real,

lon real,

reg text,

squawk int,

primary key (fp)

);


It is an error to select a column that doesn?t exist?


sqlite> select fp from flightplans;

Error: no such column: fp

But if I select a column that doesn?t exist within an embedded subquery, it is 
not an error?


sqlite> delete from inflight where fp in (select fp from flightplans);

sqlite>

(In the above example, unless I am mistaken, it should produce more or less the 
same ?no such column? error.)

In my ?real life? version of this stuff where it has a fair number of rows in 
the tables, it appears to be an infinite loop, like with < 100K rows in each 
table I aborted the statement after more than 20 minutes of CPU time.


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


___
 Gunter Hick
Software Engineer
Scientific Games International GmbH
FN 157284 a, HG Wien
Klitschgasse 2-4, A-1130 Vienna, Austria
Tel: +43 1 80100 0
E-Mail: hick at scigames.at

This communication (including any attachments) is intended for the use of the 
intended recipient(s) only and may contain information that is confidential, 
privileged or legally protected. Any unauthorized use or dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please immediately notify the sender by return e-mail message and 
delete all copies of the original communication. Thank you for your cooperation.




[sqlite] bug when columns are missing in embedded subselect

2015-12-15 Thread Stephen Chrzanowski
I work for a flight planning software house, so I had to take a double-look
at this.  Competition, eh? ;)

On Tue, Dec 15, 2015 at 4:14 PM, Richard Hipp  wrote:

>
>
> Interesting timing:  I was monitoring an inbound flight on flightaware
> when this issue report arrived in my inbox.  :-)
>
> --
> D. Richard Hipp
> drh at sqlite.org
> ___
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>


[sqlite] bug when columns are missing in embedded subselect

2015-12-15 Thread Karl Lehenbauer
Consider the following table definitions:


DROP TABLE IF EXISTS flightplans;


CREATE TABLE flightplans (

id text NOT NULL,

ident text,

recvd integer,

orig text,

dest text,

PRIMARY KEY (id)

);



DROP TABLE IF EXISTS inflight;


CREATE TABLE inflight (

fp text,

ident text,

alt integer,

clock integer NOT NULL DEFAULT 0,

gs integer,

heading integer,

lat real,

lon real,

reg text,

squawk int,

primary key (fp)

);


It is an error to select a column that doesn?t exist?


sqlite> select fp from flightplans;

Error: no such column: fp

But if I select a column that doesn?t exist within an embedded subquery, it is 
not an error?


sqlite> delete from inflight where fp in (select fp from flightplans);

sqlite>

(In the above example, unless I am mistaken, it should produce more or less the 
same ?no such column? error.)

In my ?real life? version of this stuff where it has a fair number of rows in 
the tables, it appears to be an infinite loop, like with < 100K rows in each 
table I aborted the statement after more than 20 minutes of CPU time.




[sqlite] bug when columns are missing in embedded subselect

2015-12-15 Thread Richard Hipp
On 12/15/15, Karl Lehenbauer  wrote:
>
> sqlite> select fp from flightplans;
>
> Error: no such column: fp
>
> But if I select a column that doesn?t exist within an embedded subquery, it
> is not an error?
>
> sqlite> delete from inflight where fp in (select fp from flightplans);
>

The "fp" in the subquery resolves to the "inflight" table of the outer
query.  In other words, the subquery is acting like a correlated
subquery.  This is confusing, I know, but it is the Right Thing.
PosgreSQL does the same.

Interesting timing:  I was monitoring an inbound flight on flightaware
when this issue report arrived in my inbox.  :-)

-- 
D. Richard Hipp
drh at sqlite.org