Re: [sqlite] Maintaing a Last updated timestamp column using triggers

2020-03-12 Thread Keith Medcalf
>So is "julianday('now')" non-deterministic while "julianday()" _is_ >deterministic? That seems a little weird considering they're the same >thing... right? Yes. Same as "datetime(julianday(), '+1 day')" and datetime(datetime(), '+1 day') are deterministic but "datetime('now', '+1 day')" is not

Re: [sqlite] Maintaing a Last updated timestamp column using triggers

2020-03-12 Thread David Raymond
> Alternatively, you can use the new GENERATED ALWAYS AS (...) STORED to make > it an automatically updated stored field and you do not need triggers at all, > just a version of SQLite3 that does generated columns (version 3.31.0 from > 2020-01-22 or later). > > create table MyData > ( > id

Re: [sqlite] Maintaing a Last updated timestamp column using triggers

2020-03-12 Thread Keith Medcalf
On Thursday, 12 March, 2020 09:37, David Blake wrote: >What stops the >UPDATE ports SET timeofday = CURRENT_TIMESTAMP WHERE id = NEW.id ; >from also triggering the AFTER UPDATE ON recursively? >Perhaps a pragma or inSQLite are triggers non-recursive by default? >I am using (now I have by

Re: [sqlite] Maintaing a Last updated timestamp column using triggers

2020-03-12 Thread Simon Slavin
On 12 Mar 2020, at 3:36pm, David Blake wrote: > What stops the > UPDATE ports SET timeofday = CURRENT_TIMESTAMP WHERE id = NEW.id ; > from also triggering the AFTER UPDATE ON recursively? > > Perhaps a pragma or inSQLite are triggers non-recursive by default? Bingo.

Re: [sqlite] Maintaing a Last updated timestamp column using triggers

2020-03-12 Thread David Raymond
> What stops the > UPDATE ports SET timeofday = CURRENT_TIMESTAMP WHERE id = NEW.id ; > from also triggering the AFTER UPDATE ON recursively? > > Perhaps a pragma or inSQLite are triggers non-recursive by default? > > I am using (now I have by semi-colons right) > CREATE TRIGGER tgrUpdate AFTER

Re: [sqlite] Maintaing a Last updated timestamp column using triggers

2020-03-12 Thread Ling, Andy
>Thanks Andy >> In addition, the role of the "when" clause is unclear. Is it necessary? >> >> I don't think it is. I have a very similar trigger which I've been >> using for several years And it doesn't have the where... >> >> CREATE TRIGGER [UpdatePortTime] AFTER UPDATE ON ports FOR EACH ROW

Re: [sqlite] Maintaing a Last updated timestamp column using triggers

2020-03-12 Thread David Blake
Thanks Andy > In addition, the role of the "when" clause is unclear. Is it necessary? > > I don't think it is. I have a very similar trigger which I've been using > for several years > And it doesn't have the where... > > CREATE TRIGGER [UpdatePortTime] AFTER UPDATE ON ports > FOR EACH ROW >

Re: [sqlite] Maintaing a Last updated timestamp column using triggers

2020-03-12 Thread Ling, Andy
>On 12/03/2020 08:47, David Blake wrote: >> I'm looking for an easy way to maintain a last updated column for each >> record in several tables and considering if using a triggers is viable. >> >> I thought that defining a trigger like this on each table would work >> >> CREATE TRIGGER

Re: [sqlite] Maintaing a Last updated timestamp column using triggers

2020-03-12 Thread Jean-Luc Hainaut
On 12/03/2020 08:47, David Blake wrote: I'm looking for an easy way to maintain a last updated column for each record in several tables and considering if using a triggers is viable. I thought that defining a trigger like this on each table would work CREATE TRIGGER my_update_trigger BEFORE

Re: [sqlite] Maintaing a Last updated timestamp column using triggers

2020-03-12 Thread David Blake
Ha, my error - missing ";" in the UPDATE clause but I was blind. On Thu, 12 Mar 2020 at 08:18, David Blake wrote: > Thanks for such a swift reply, good to know that it should work (without > typos) > > >Thank you very much for keeping the error message secret. > > near "END": syntax error: > >

Re: [sqlite] Maintaing a Last updated timestamp column using triggers

2020-03-12 Thread David Blake
Thanks for such a swift reply, good to know that it should work (without typos) >Thank you very much for keeping the error message secret. near "END": syntax error: I'm testing out ideas using DB Browser, but will try in my app and see if this is just a DB Browser issue On Thu, 12 Mar 2020 at

Re: [sqlite] Maintaing a Last updated timestamp column using triggers

2020-03-12 Thread Clemens Ladisch
David Blake wrote: > CREATE TRIGGER my_update_trigger BEFORE UPDATE ON My_table > FOR EACH ROW WHEN NEW.lastupdated < OLD. lastupdated > BEGIN > UPDATE song SET lastupdated = DATETIME('now') WHERE id = NEW.id > END > > The WHEN clause is an attempt to avoid infinite recursion that