Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-17 Thread David Raymond
My thinking on this is use a trigger or two. So if you have fields Date and Tiebreaker (as mentioned in the other replies) ... Date text, Tiebreaker int, ... Have it so if you insert it with a given Tiebreaker value it increments things after that, or if you give it null it puts it at the end

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-16 Thread Chris Locke
But be careful, as you can't change all records from 3 to 4 and then 4 to 5, as the 4 to 5 will contain the records you've just moved from 3 to 4 Canofworms.jpg. ;) Thanks, Chris On 15 Oct 2016 5:46 p.m., "Richard Damon" wrote: > On 10/15/16 12:15 PM, Simon

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Simon Slavin
On 16 Oct 2016, at 12:32am, Keith Medcalf wrote: > The whole reason for using a "manual sortation field" is so that a human can > decide what order to display the data in via a "manual" operation. You answered the question. To get as close to the OP's requirements as

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Keith Medcalf
On Saturday, 15 October, 2016 16:44, Richard Damon , wrote: > Summary of what I have seen: > Schema for table has an auto-increment primary key, and a Date-Time > field (which has duplicate values) > Records are to be retrieved in Date-Time order, with duplicate

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Simon Slavin
On 15 Oct 2016, at 11:43pm, Richard Damon wrote: > My thought is that if the first level of sort IS by Date-Time, and then by > some other condition, then the real solution is to use an ORDER BY clause on > the Date-Time field and then some other field to implement

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Richard Damon
Summary of what I have seen: Schema for table has an auto-increment primary key, and a Date-Time field (which has duplicate values) Records are to be retrieved in Date-Time order, with duplicate values needing to be retrieved in a consistent (and perhaps even specified by something else)

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Luca Olivetti
El 15/10/16 a les 20:53, Jens Alfke ha escrit: [*] I have to insert records in the given order but the user may occasionally rearrange them. What happens if the user makes a series of rearrangements that triggers a collision? It’s not that far fetched; all I have to do is, one at a time,

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Delvin
Afternoon all, I am replying to this thread because I am a little confused here. From what I have gotten from this thread, someone wants to be able to insert a record into a table based on an arbitrary record number (i.e. if a table already has records number 1, 2, 3, 4, etc., have the

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread J Decker
On Sat, Oct 15, 2016 at 11:58 AM, Keith Medcalf wrote: > > I'd just sort the data into the order I wanted the result set presented in > using an ORDER BY clause on the SELECT which retrieves the data ... > One other thought I saw someone else propose a while ago... treat

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread J Decker
On Sat, Oct 15, 2016 at 10:18 AM, Stephen Chrzanowski wrote: > What you want to do is called using a linked list. Each record knows what > its previous record is. > > SQLite doesn't exactly have that capability directly. No SQL engine that I > know of has the capability.

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Keith Medcalf
I'd just sort the data into the order I wanted the result set presented in using an ORDER BY clause on the SELECT which retrieves the data ... > > On Oct 15, 2016, at 11:12 AM, Keith Medcalf wrote: > > > >> Is there a way to do this automagically (like a specialized INSERT

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Jens Alfke
> On Oct 15, 2016, at 11:38 AM, Luca Olivetti wrote: > > I'm aware of the limitation but for my application[*] it is perfectly fine, > maybe it is also ok for the OP, maybe it isn't. OK, but if you’re proposing a solution that you know has major limitations, I think it’s a

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Jens Alfke
> On Oct 15, 2016, at 11:12 AM, Keith Medcalf wrote: > >> Is there a way to do this automagically (like a specialized INSERT >> command?) in Sqlite? > > Unfortunately no, there is no way to do this on *ANY* database that uses the > relational database model. There’s no

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Luca Olivetti
El 15/10/16 a les 19:49, Jens Alfke ha escrit: On Oct 15, 2016, at 7:42 AM, Luca Olivetti wrote: Instead of an autoincrement you could increment it manually in, say, 1000 increments. Then, when you have to insert something between 1000 and 2000 you just use 1500.

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Keith Medcalf
On Friday, 14 October, 2016 07:29, Thom Wharton wrote: > I have a table of records in a Sqlite DB. It contains 5 records. Each > record has a time-stamp which is not guaranteed to be unique. To > preserve order (which is important in my project), I've given

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Jens Alfke
> On Oct 15, 2016, at 7:42 AM, Luca Olivetti wrote: > > Instead of an autoincrement you could increment it manually in, say, 1000 > increments. > Then, when you have to insert something between 1000 and 2000 you just use > 1500. Unfortunately this breaks down after log2(1000)

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Stephen Chrzanowski
What you want to do is called using a linked list. Each record knows what its previous record is. SQLite doesn't exactly have that capability directly. No SQL engine that I know of has the capability. Each row is unaware of any other row in that table. That row is a unique entity to itself,

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Richard Damon
On 10/15/16 12:15 PM, Simon Slavin wrote: On 14 Oct 2016, at 2:29pm, Thom Wharton wrote: I want to be able to programmatically insert a new record anywhere in that table. Let's suppose I want to create a new record between the records whose ID are 2 and 3.

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Simon Slavin
On 14 Oct 2016, at 2:29pm, Thom Wharton wrote: > I want to be able to programmatically insert a new record anywhere in that > table. Let's suppose I want to create a new record between the records whose > ID are 2 and 3. This new record would need to take the

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Luca Olivetti
El 14/10/16 a les 15:29, Thom Wharton ha escrit: Hello, I have a table of records in a Sqlite DB. It contains 5 records. Each record has a time-stamp which is not guaranteed to be unique. To preserve order (which is important in my project), I've given the table an integer primary key (called

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Richard Damon
If you sort rule is by Date (and time) and ID as a tie breaker, then you should have your sort key be THAT, not just your ID field (I.e., your index/order would be Data, ID not just ID) An auto-increment primary key is to give every record a unique id to refer to it, the only order that it

Re: [sqlite] Inserting a new record (anywhere) into a table of ordered records that have an integer auto-increment primary key

2016-10-15 Thread Igor Tandetnik
On 10/14/2016 9:29 AM, Thom Wharton wrote: IDDate Type Size Data 110OCT-08:13:47 Ether28sddsgsd... 210OCT-08:13:52 Ether77fdasfdsdsddssdg... 310OCT-08:13:52 Ether44zeasfkkfa... 4