[sqlite] "Circular" order by

2016-03-11 Thread Kees Nuyt
On Fri, 11 Mar 2016 09:05:27 +0200, R Smith wrote: > >On 2016/03/11 5:52 AM, Stephen Chrzanowski wrote: >> On Thu, Mar 10, 2016 at 2:16 PM, R Smith wrote: >> >> >>> I do this kind of thing so often when filling a selection box for instance: >>>SELECT 'None' >>> UNION ALL >>>SELECT City F

[sqlite] "Circular" order by

2016-03-11 Thread R Smith
On 2016/03/11 5:52 AM, Stephen Chrzanowski wrote: > On Thu, Mar 10, 2016 at 2:16 PM, R Smith wrote: > > >> I do this kind of thing so often when filling a selection box for instance: >>SELECT 'None' >> UNION ALL >>SELECT City FROM Countrylist WHERE Country = :1 >> UNION ALL >> SELECT Cit

[sqlite] "Circular" order by

2016-03-10 Thread Stephen Chrzanowski
On Thu, Mar 10, 2016 at 2:16 PM, R Smith wrote: > > I do this kind of thing so often when filling a selection box for instance: > SELECT 'None' > UNION ALL > SELECT City FROM Countrylist WHERE Country = :1 > UNION ALL > SELECT City FROM Countrylist WHERE Country <> :1 ORDER BY City > > Which

[sqlite] "Circular" order by

2016-03-10 Thread Alberto Wu
On 03/10/16 20:16, R Smith wrote: >> Hmm, does this work any better? >> >> SELECT id FROM t >> ORDER BY id < 'pen' desc, id; > > It works, but not better. Indeed. Any operation in ORDER BY (even things like "ORDER BY id||''") result in scan + temp b-tree. Thanks again. -- Alberto

[sqlite] "Circular" order by

2016-03-10 Thread R Smith
On 2016/03/10 8:37 PM, James K. Lowden wrote: > On Thu, 10 Mar 2016 10:17:57 +0100 > Alberto Wu wrote: > >> On 03/09/16 23:30, James K. Lowden wrote: SELECT P.id FROM ( SELECT 0 AS sect, id FROM t WHERE id >= 'pen' UNION ALL SELECT 1, id FROM t WHERE id < 'pen'

[sqlite] "Circular" order by

2016-03-10 Thread James K. Lowden
On Thu, 10 Mar 2016 21:16:28 +0200 R Smith wrote: > > Hmm, does this work any better? > > > > SELECT id FROM t > > ORDER BY id < 'pen' desc, id; > > It works, but not better. I think it was Igor who proposed similar > (if not, apologies) which of course produces the correct result, but >

[sqlite] "Circular" order by

2016-03-10 Thread James K. Lowden
On Thu, 10 Mar 2016 10:17:57 +0100 Alberto Wu wrote: > On 03/09/16 23:30, James K. Lowden wrote: > >> SELECT P.id FROM ( > >> SELECT 0 AS sect, id FROM t WHERE id >= 'pen' > >> UNION ALL > >> SELECT 1, id FROM t WHERE id < 'pen' > >> ) AS P > >> ORDER BY P.sect, P.id > >> ; > > > > T

[sqlite] "Circular" order by

2016-03-10 Thread Alberto Wu
On 03/09/16 23:30, James K. Lowden wrote: >> SELECT P.id FROM ( >> SELECT 0 AS sect, id FROM t WHERE id >= 'pen' >> UNION ALL >> SELECT 1, id FROM t WHERE id < 'pen' >> ) AS P >> ORDER BY P.sect, P.id >> ; > > This is the correct answer. Hi, unfortunately the correct answer comes w

[sqlite] "Circular" order by

2016-03-09 Thread R Smith
On 2016/03/09 8:08 PM, Alberto Wu wrote: > On 03/09/16 17:26, R Smith wrote: >> Firstly, this is the best method - one I would use. UNION ALL is quite >> efficient. >> Secondly, the order by will be honoured - you can refer to the SQL >> standard for that even, it's an axiom of the output and pr

[sqlite] "Circular" order by

2016-03-09 Thread Alberto Wu
On 03/09/16 17:26, R Smith wrote: > Firstly, this is the best method - one I would use. UNION ALL is quite > efficient. > Secondly, the order by will be honoured - you can refer to the SQL > standard for that even, it's an axiom of the output and probably not > even considered "needed" to mention.

[sqlite] "Circular" order by

2016-03-09 Thread R Smith
On 2016/03/09 6:07 PM, Alberto Wu wrote: > Hi all, > > I'm looking for suggestions... > What I want to achieve is to "roll" the result set of a query around by > a certain amount (as in offset + wrap around). > > For example, given that: > CREATE TABLE t (id TEXT NOT NULL PRIMARY KEY); > INSERT I

[sqlite] "Circular" order by

2016-03-09 Thread James K. Lowden
On Wed, 9 Mar 2016 20:43:14 +0200 R Smith wrote: > SELECT P.id FROM ( > SELECT 0 AS sect, id FROM t WHERE id >= 'pen' > UNION ALL > SELECT 1, id FROM t WHERE id < 'pen' > ) AS P > ORDER BY P.sect, P.id > ; This is the correct answer. I'm not sure what you meant by "axiom" in your

[sqlite] "Circular" order by

2016-03-09 Thread Alberto Wu
Hi all, I'm looking for suggestions... What I want to achieve is to "roll" the result set of a query around by a certain amount (as in offset + wrap around). For example, given that: CREATE TABLE t (id TEXT NOT NULL PRIMARY KEY); INSERT INTO t VALUES ('pen'), ('tree'), ('desk'), ('car'); I would