Re: [sqlite] Fwd: inserting new data only

2020-02-26 Thread Jose Isaias Cabrera
James K. Lowden, on Wednesday, February 26, 2020 11:55 AM, wrote... > > On Tue, 25 Feb 2020 12:02:24 -0500 > Przemek Klosowski wrote: > > > and I want to avoid storing repetitive data, so that the database > > should contain > > 10:32 12 > > 10:35 15 > > 10:39 13 > > 10:46 18 > > where only

Re: [sqlite] Fwd: inserting new data only

2020-02-26 Thread Przemek Klosowski
On Wed, Feb 26, 2020 at 11:56 AM James K. Lowden wrote: > > and I want to avoid storing repetitive data, so that the database > > should contain > > [...] > > only the earliest time with the unchanging value is stored. > > Be careful what you wish for. Usually "avoid storing" is a proxy for >

Re: [sqlite] Fwd: inserting new data only

2020-02-26 Thread James K. Lowden
On Tue, 25 Feb 2020 12:02:24 -0500 Przemek Klosowski wrote: > and I want to avoid storing repetitive data, so that the database > should contain > 10:32 12 > 10:35 15 > 10:39 13 > 10:46 18 > where only the earliest time with the unchanging value is stored. Be careful what you wish for.

Re: [sqlite] Fwd: inserting new data only

2020-02-25 Thread Keith Medcalf
>From: sqlite-users On >Behalf Of Keith Medcalf >Sent: Tuesday, 25 February, 2020 14:44 >To: SQLite mailing list >Subject: Re: [sqlite] Fwd: inserting new data only > > >If you are going to do it in all in one insert statement rather than >using a before trigge

Re: [sqlite] Fwd: inserting new data only

2020-02-25 Thread Keith Medcalf
t;Subject: Re: [sqlite] Fwd: inserting new data only > > >On Tuesday, 25 February, 2020 12:23, Przemek Klosowski > wrote: > >>On Tue, Feb 25, 2020 at 1:18 PM Keith Medcalf >wrote: > >>> create table data >>> ( >>> keytext primary key, >

Re: [sqlite] Fwd: inserting new data only

2020-02-25 Thread Keith Medcalf
On Tuesday, 25 February, 2020 12:23, Przemek Klosowski wrote: >On Tue, Feb 25, 2020 at 1:18 PM Keith Medcalf wrote: >> create table data >> ( >> keytext primary key, >> data integer not null >> ) >> without rowid; >> >> -- insert into data select ?, ? as value where value IS

Re: [sqlite] Fwd: inserting new data only

2020-02-25 Thread David Raymond
Awesome---exactly what's needed. The monotonicity of the time key variable is assured by how the data is collected---but is there a way to express that in sqlite? create table data ( key text primary key check (julianday(key) > julianday(select max(key) from data), data integer not null);

Re: [sqlite] Fwd: inserting new data only

2020-02-25 Thread Przemek Klosowski
On Tue, Feb 25, 2020 at 1:18 PM Keith Medcalf wrote: > create table data > ( > keytext primary key, > data integer not null > ) > without rowid; > > -- insert into data select (?, ? as value where value IS NOT (select data > from (select max(key), data from data)); >.. >

Re: [sqlite] Fwd: inserting new data only

2020-02-25 Thread Keith Medcalf
Keith Medcalf >Sent: Tuesday, 25 February, 2020 11:18 >To: 'SQLite mailing list' >Subject: RE: [sqlite] Fwd: inserting new data only > > >create table data >( >keytext primary key, >data integer not null >) >without rowid; > >-- inser

Re: [sqlite] Fwd: inserting new data only

2020-02-25 Thread Keith Medcalf
create table data ( keytext primary key, data integer not null ) without rowid; -- insert into data select (?, ? as value where value IS NOT (select data from (select max(key), data from data)); insert into data select '10:32', 12 as value where value IS NOT (select data from

Re: [sqlite] Fwd: inserting new data only

2020-02-25 Thread Przemek Klosowski
On Tue, Feb 25, 2020 at 1:03 PM John McKown wrote: > > I am storing time series data arriving from a sensor into (time,value) > > records, like so: > > 10:32 12 > > 10:35 15 > > 10:37 15 > > 10:39 13 > > 10:43 13 > > 10:46 18 > > > > and I want to avoid storing repetitive data, so that the

Re: [sqlite] Fwd: inserting new data only

2020-02-25 Thread Przemek Klosowski
On Tue, Feb 25, 2020 at 12:22 PM David Raymond wrote: > > A before trigger which uses the raise function would stop it from getting > inserted in the first place. > > create trigger cull > before insert on tbl > when new.value = (select value from tbl order by time desc limit 1) > begin > select

Re: [sqlite] Fwd: inserting new data only

2020-02-25 Thread John McKown
On Tue, Feb 25, 2020 at 11:03 AM Przemek Klosowski < przemek.klosowski+sql...@gmail.com> wrote: > I am storing time series data arriving from a sensor into (time,value) > records, like so: > 10:32 12 > 10:35 15 > 10:37 15 > 10:39 13 > 10:43 13 > 10:46 18 > > and I want to avoid storing

Re: [sqlite] Fwd: inserting new data only

2020-02-25 Thread David Raymond
A before trigger which uses the raise function would stop it from getting inserted in the first place. create trigger cull before insert on tbl when new.value = (select value from tbl order by time desc limit 1) begin select raise(ignore); end; Or if you want it to actually return an error to