[sqlite] unexpected behavior with CROSS and LEFT JOIN together

2010-02-24 Thread Mark Brand
Hi, I've run into some puzzling behavior. I've tried to distill it to a minimal case. In the final SELECT query below, the last LEFT JOIN clause seems have the effect of an INNER JOIN in that its condition limits the rows returned. I can rewrite the query to get the desired result using a UNION

Re: [sqlite] unexpected behavior with CROSS and LEFT JOIN together

2010-02-24 Thread Pavel Ivanov
It's pretty strange how you try to join with some table not even mentioning any column of that table in the joining condition. I bet behavior is not defined for such cases in SQL standard and you're getting some interpretation of such query. Probably this query will return what you want: SELECT

Re: [sqlite] unexpected behavior with CROSS and LEFT JOIN together

2010-02-24 Thread Mark Brand
It's pretty strange how you try to join with some table not even mentioning any column of that table in the joining condition. I bet behavior is not defined for such cases in SQL standard and you're getting some interpretation of such query. I'm not aware of any requirement that a JOIN

Re: [sqlite] unexpected behavior with CROSS and LEFT JOIN together

2010-02-24 Thread Igor Tandetnik
Mark Brand mabr...@mabrand.nl wrote: --Gives unexpected results SELECT c1.cur cur1, c2.cur cur2, COALESCE(self.rate, x.rate) rate FROM currency c1 CROSS JOIN currency c2 LEFT JOIN exchange x ON x.cur1=c1.cur AND x.cur2=c2.cur LEFT JOIN (SELECT 1 rate) self ON c1.cur=c2.cur; /*

Re: [sqlite] unexpected behavior with CROSS and LEFT JOIN together

2010-02-24 Thread ve3meo
Igor Tandetnik itandet...@mvps.org wrote in message news:hm45gu$s5...@dough.gmane.org... Mark Brand mabr...@mabrand.nl wrote: --Gives unexpected results SELECT c1.cur cur1, c2.cur cur2, COALESCE(self.rate, x.rate) rate FROM currency c1 CROSS JOIN currency c2 LEFT JOIN exchange x ON

Re: [sqlite] unexpected behavior with CROSS and LEFT JOIN together

2010-02-24 Thread ve3meo
ve3meo holden_fam...@sympatico.ca wrote in message news:hm47t5$5l...@dough.gmane.org... Igor Tandetnik itandet...@mvps.org wrote in message news:hm45gu$s5...@dough.gmane.org... Mark Brand mabr...@mabrand.nl wrote: --Gives unexpected results SELECT c1.cur cur1, c2.cur cur2,

Re: [sqlite] unexpected behavior with CROSS and LEFT JOIN together

2010-02-24 Thread Pavel Ivanov
Does INDEX sqlite_autoindex_currency_1 contain only pointers to the identical currencies? First of all AFAIK 'PRIMARY KEY' implies uniqueness of the column. And second: I bet if you execute 'PRAGMA case_sensitive_like = true' then plans will be the same. See

Re: [sqlite] unexpected behavior with CROSS and LEFT JOIN together

2010-02-24 Thread D. Richard Hipp
On Feb 24, 2010, at 5:20 PM, Pavel Ivanov wrote: Does INDEX sqlite_autoindex_currency_1 contain only pointers to the identical currencies? First of all AFAIK 'PRIMARY KEY' implies uniqueness of the column. And second: I bet if you execute 'PRAGMA case_sensitive_like = true' then plans will

Re: [sqlite] unexpected behavior with CROSS and LEFT JOIN together

2010-02-24 Thread Igor Tandetnik
D. Richard Hipp d...@hwaci.com wrote: This problem has existed in SQLite forever and has never been seen before. So it is obscure. The simple fix is to put the ON clause on the CROSS JOIN where it belongs. Does CROSS JOIN allow an ON clause? That doesn't make much sense. I guess I'm missing

Re: [sqlite] unexpected behavior with CROSS and LEFT JOIN together

2010-02-24 Thread ve3meo
I posted the following and it didn't appear - I probably hit Reply to Sender instead of Reply Group: Does INDEX sqlite_autoindex_currency_1 contain only pointers to the identical currencies? Tom This little change also works: ON +c1.cur=c2.cur; or ON c1.cur=+c2.cur; Along with LIKE, that

Re: [sqlite] unexpected behavior with CROSS and LEFT JOIN together

2010-02-24 Thread D. Richard Hipp
On Feb 24, 2010, at 5:45 PM, Igor Tandetnik wrote: D. Richard Hipp d...@hwaci.com wrote: This problem has existed in SQLite forever and has never been seen before. So it is obscure. The simple fix is to put the ON clause on the CROSS JOIN where it belongs. Does CROSS JOIN allow an ON

Re: [sqlite] unexpected behavior with CROSS and LEFT JOIN together

2010-02-24 Thread Igor Tandetnik
D. Richard Hipp d...@hwaci.com wrote: On Feb 24, 2010, at 5:45 PM, Igor Tandetnik wrote: D. Richard Hipp d...@hwaci.com wrote: This problem has existed in SQLite forever and has never been seen before. So it is obscure. The simple fix is to put the ON clause on the CROSS JOIN where it