Re: [sqlite] INTEGER PRIMARY KEY AUTOINCREMENT

2017-06-14 Thread Peter Aronson
On 6/14/2017 5:42 AM, R Smith wrote: On 2017/06/14 7:08 AM, Wout Mertens wrote: Is there a way to specify the starting rowid when using autoincrement? Or should I insert and then remove a row with the id set to one less than the desired id? This is quite easy, but first it is helpful to

[sqlite] INTEGER PRIMARY KEY AUTOINCREMENT

2017-06-14 Thread wout.mertens
Thank you so much all! This mailinglist is amazing :) ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Re: [sqlite] INTEGER PRIMARY KEY AUTOINCREMENT

2017-06-14 Thread R Smith
On 2017/06/14 7:08 AM, Wout Mertens wrote: Is there a way to specify the starting rowid when using autoincrement? Or should I insert and then remove a row with the id set to one less than the desired id? This is quite easy, but first it is helpful to understand the mechanism by which SQLite

Re: [sqlite] INTEGER PRIMARY KEY AUTOINCREMENT

2017-06-14 Thread J Decker
from https://sqlite.org/autoinc.html On an INSERT, if the ROWID or INTEGER PRIMARY KEY column is not explicitly given a value, then it will be filled automatically with an unused integer, usually one more than the largest ROWID currently in use. This is true regardless of whether or not the

[sqlite] INTEGER PRIMARY KEY AUTOINCREMENT

2017-06-13 Thread Wout Mertens
Is there a way to specify the starting rowid when using autoincrement? Or should I insert and then remove a row with the id set to one less than the desired id? ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org

Re: [sqlite] INTEGER PRIMARY KEY

2017-06-12 Thread David Burgess
> But we have to preserve backwards compatibility - even with bugs > like this. ​How about a new release? i.e. sqlite4 No backward compatibilty issues.​ ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org

Re: [sqlite] INTEGER PRIMARY KEY

2017-06-12 Thread Scott Robison
On Jun 12, 2017 8:26 PM, "Keith Medcalf" wrote: Additionally, declaring NOT NULL or NULL is ignored. CHECK constraints are honoured. DEFAULT values are ignored. so CREATE TABLE x(id INTEGER NULL PRIMARY KEY CHECK (id>1000) DEFAULT (-1)); & CREATE TABLE x(id INTEGER NULL

Re: [sqlite] INTEGER PRIMARY KEY

2017-06-12 Thread Scott Robison
On Jun 12, 2017 5:43 PM, "Richard Hipp" wrote: On 6/13/17, Scott Robison wrote: > > Is it fair to say that the rowid aliasing behavior does not require > (by design) the incantation "INTEGER PRIMARY KEY" (all three words in > that order as the "type")

Re: [sqlite] INTEGER PRIMARY KEY

2017-06-12 Thread Keith Medcalf
ers [mailto:sqlite-users-boun...@mailinglists.sqlite.org] > On Behalf Of Richard Hipp > Sent: Monday, 12 June, 2017 17:44 > To: SQLite mailing list > Subject: Re: [sqlite] INTEGER PRIMARY KEY > > On 6/13/17, Scott Robison <sc...@casaderobison.com> wrote: > > > > Is

Re: [sqlite] INTEGER PRIMARY KEY

2017-06-12 Thread Richard Hipp
On 6/13/17, Scott Robison wrote: > > Is it fair to say that the rowid aliasing behavior does not require > (by design) the incantation "INTEGER PRIMARY KEY" (all three words in > that order as the "type") as long as the type is INTEGER and the > constraint PRIMARY KEY

Re: [sqlite] INTEGER PRIMARY KEY

2017-06-12 Thread Scott Robison
On Mon, Jun 12, 2017 at 4:20 PM, Simon Slavin wrote: > > > On 12 Jun 2017, at 11:01pm, Scott Robison wrote: > >> Is it fair to say that the rowid aliasing behavior does not require >> (by design) the incantation "INTEGER PRIMARY KEY" (all three

Re: [sqlite] INTEGER PRIMARY KEY

2017-06-12 Thread Simon Slavin
On 12 Jun 2017, at 11:01pm, Scott Robison wrote: > Is it fair to say that the rowid aliasing behavior does not require > (by design) the incantation "INTEGER PRIMARY KEY" (all three words in > that order as the "type") as long as the type is INTEGER and the >

[sqlite] INTEGER PRIMARY KEY

2017-06-12 Thread Scott Robison
This is as much out of curiosity as anything. I know that to get the rowid aliasing behavior for a table one must define the column type as INTEGER and using the constraint PRIMARY KEY. Something like: CREATE TABLE A(B INTEGER PRIMARY KEY); In testing this afternoon I was curious if I could give

Re: [sqlite] 'INTEGER PRIMARY KEY' start value

2014-10-19 Thread Luuk
On 19-10-2014 17:48, Keith Medcalf wrote: for a table test(i integer primary key, j integer) the new i (rowid) is as follows: test.i = case when test.i is not null then test.i else case max(test.i) when null then 1 else max(test.i)+1 end end if you add the autoincrement keyword, then the

Re: [sqlite] 'INTEGER PRIMARY KEY' start value

2014-10-19 Thread Keith Medcalf
ion commits. >-Original Message- >From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users- >boun...@sqlite.org] On Behalf Of Luuk >Sent: Sunday, 19 October, 2014 08:10 >To: sqlite-users@sqlite.org >Subject: Re: [sqlite] 'INTEGER PRIMARY KEY' start value > >

Re: [sqlite] 'INTEGER PRIMARY KEY' start value

2014-10-19 Thread Luuk
On 19-10-2014 15:27, Baruch Burstein wrote: Is the rowid/'INTEGER PRIMARY KEY' field that is not entered manually guaranteed to start from 1? Or at least from a positive number? no C:\temp>sqlite3 SQLite version 3.8.4.3 2014-04-03 16:53:12 Enter ".help" for usage hints. Connected to a

Re: [sqlite] 'INTEGER PRIMARY KEY' start value

2014-10-19 Thread Simon Slavin
On 19 Oct 2014, at 2:27pm, Baruch Burstein wrote: > Is the rowid/'INTEGER PRIMARY KEY' field that is not entered manually > guaranteed to start from 1? Or at least from a positive number? See the section 'Background' in for the

[sqlite] 'INTEGER PRIMARY KEY' start value

2014-10-19 Thread Baruch Burstein
Is the rowid/'INTEGER PRIMARY KEY' field that is not entered manually guaranteed to start from 1? Or at least from a positive number? -- ˙uʍop-ǝpısdn sı ɹoʇıuoɯ ɹnoʎ 'sıɥʇ pɐǝɹ uɐɔ noʎ ɟı ___ sqlite-users mailing list sqlite-users@sqlite.org

Re: [sqlite] INTEGER PRIMARY KEY and SQLITE_ENABLE_STAT2

2011-10-11 Thread GB
GB schrieb am 24.08.2011 19:59: Hi all, I have a table like this: CREATE TABLE t (itemID INTEGER PRIMARY KEY, createdAt DATETIME); CREATE INDEX createIdx on t(createdAt); SQLite is compiled using SQLITE_ENABLE_STAT2 and table is ANALYZEd with current content. When perfoming a Statement like

Re: [sqlite] INTEGER PRIMARY KEY and SQLITE_ENABLE_STAT2

2011-08-30 Thread GB
GB schrieb am 25.08.2011 18:27: Simon Slavin schrieb am 25.08.2011 02:00: Had you thought of creating an explicit index on the rowid column, then running ANALYZE again ? Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org

Re: [sqlite] INTEGER PRIMARY KEY and SQLITE_ENABLE_STAT2

2011-08-25 Thread GB
Simon Slavin schrieb am 25.08.2011 02:00: > Had you thought of creating an explicit index on the rowid column, then > running ANALYZE again ? > > Simon. > ___ > sqlite-users mailing list > sqlite-users@sqlite.org >

Re: [sqlite] INTEGER PRIMARY KEY and SQLITE_ENABLE_STAT2

2011-08-25 Thread Carlos Rocha
> > It seems equally logical to me that one of A or B might be evaluated, and if > it were false, then the other might not be evaluated. I don't think so if efficiency matters. Of course the rule could be to evaluated from right to left instead, but it's good to have just one rule, and again,

Re: [sqlite] INTEGER PRIMARY KEY and SQLITE_ENABLE_STAT2

2011-08-25 Thread Alex Bowden
logical? It seems equally logical to me that one of A or B might be evaluated, and if it were false, then the other might not be evaluated. And it would be logical to choose which of A or B to evaluated on a predicted cost and probability of an advantageous false result. but hay. Who said

Re: [sqlite] INTEGER PRIMARY KEY and SQLITE_ENABLE_STAT2

2011-08-24 Thread Simon Slavin
On 24 Aug 2011, at 11:18pm, GB wrote: > Well, that is exactly what the sqlite_stat2 table is meant for. It's > information is supposed to make the query planner able to decide upon > the usefulness of an index. Unfortunately, histogram information is not > collected for the implicit rowid

Re: [sqlite] INTEGER PRIMARY KEY and SQLITE_ENABLE_STAT2

2011-08-24 Thread GB
Simon Slavin schrieb am 24.08.2011 23:33: > On 24 Aug 2011, at 9:59pm, GB wrote: > >> Simon Slavin schrieb am 24.08.2011 22:38: >> >>> SELECT itemID FROM t WHERE itemID>= 100 AND itemID<= 200 AND >>> createdAt>= '2011-08-01' createdAt<= '2011-08-02' >> Thank you for your thoughts but I

Re: [sqlite] INTEGER PRIMARY KEY and SQLITE_ENABLE_STAT2

2011-08-24 Thread Simon Slavin
On 24 Aug 2011, at 9:59pm, GB wrote: > Simon Slavin schrieb am 24.08.2011 22:38: > >> SELECT itemID FROM t WHERE itemID>= 100 AND itemID<= 200 AND >> createdAt>= '2011-08-01' createdAt<= '2011-08-02' > > Thank you for your thoughts but I already tried this with no different > results

Re: [sqlite] INTEGER PRIMARY KEY and SQLITE_ENABLE_STAT2

2011-08-24 Thread GB
Simon Slavin schrieb am 24.08.2011 22:38: > On 24 Aug 2011, at 6:59pm, GB wrote: > >> SELECT itemID FROM t WHERE itemID BETWEEN 100 AND 200 AND >> createdAt BETWEEN '2011-08-01' AND '2011-08-02' > Just out of curiosity, try changing both the BETWEEN formulations so it says > > SELECT

Re: [sqlite] INTEGER PRIMARY KEY and SQLITE_ENABLE_STAT2

2011-08-24 Thread Simon Slavin
On 24 Aug 2011, at 6:59pm, GB wrote: > SELECT itemID FROM t WHERE itemID BETWEEN 100 AND 200 AND > createdAt BETWEEN '2011-08-01' AND '2011-08-02' Just out of curiosity, try changing both the BETWEEN formulations so it says SELECT itemID FROM t WHERE itemID >= 100 AND itemID <=

Re: [sqlite] INTEGER PRIMARY KEY and SQLITE_ENABLE_STAT2

2011-08-24 Thread GB
No, SQLite (as well as most other database systems) does a more elaborate evaluation. I breaks the statement apart into subterms and tries to determine which one makes the most beneficial use of an index so the order of the statement does not matter. See http://www.sqlite.org/optoverview.html

Re: [sqlite] INTEGER PRIMARY KEY and SQLITE_ENABLE_STAT2

2011-08-24 Thread GB
Igor Tandetnik schrieb am 24.08.2011 20:20: > On 8/24/2011 1:59 PM, GB wrote: >> When perfoming a Statement like this: >> >> SELECT itemID FROM t WHERE itemID BETWEEN 100 AND 200 AND >> createdAt BETWEEN '2011-08-01' AND '2011-08-02' >> >> the analyzer always chooses the rowid index which

Re: [sqlite] INTEGER PRIMARY KEY and SQLITE_ENABLE_STAT2

2011-08-24 Thread Carlos Rocha
Don't know how SQLite should behave in this case, but seems logical to me that A and B would force that A is always evaluated, and B is evaluated only if A is true. I would change the order of the two betweens: SELECT itemID FROM t WHERE createdAt BETWEEN '2011-08-01' AND '2011-08-02' AND

Re: [sqlite] INTEGER PRIMARY KEY and SQLITE_ENABLE_STAT2

2011-08-24 Thread Igor Tandetnik
On 8/24/2011 1:59 PM, GB wrote: > When perfoming a Statement like this: > > SELECT itemID FROM t WHERE itemID BETWEEN 100 AND 200 AND > createdAt BETWEEN '2011-08-01' AND '2011-08-02' > > the analyzer always chooses the rowid index which results in a scan over > one million rows. It would

[sqlite] INTEGER PRIMARY KEY and SQLITE_ENABLE_STAT2

2011-08-24 Thread GB
Hi all, I have a table like this: CREATE TABLE t (itemID INTEGER PRIMARY KEY, createdAt DATETIME); CREATE INDEX createIdx on t(createdAt); SQLite is compiled using SQLITE_ENABLE_STAT2 and table is ANALYZEd with current content. When perfoming a Statement like this: SELECT itemID FROM t WHERE

Re: [sqlite] integer primary key autoincrement & sqlite_sequence

2009-06-25 Thread Igor Tandetnik
Pavel Ivanov wrote: > Could you explain why this scenario doesn't cause infinite call cycle > of the trigger by itself? Is there some protection in SQLite which > breaks such cycles? SQLite doesn't support recursive triggers: a trigger cannot call itself, directly or indirectly. SQLite keeps

Re: [sqlite] integer primary key autoincrement & sqlite_sequence

2009-06-22 Thread Dennis Cote
Oliver Peters wrote: > > I want the "normal" user only identify himself by putting his id into > the field identity and afterwards let the system decide in what field to > put his id (INSERT = creator, UPDATE = editor). Doing this for every > record I can show who created it and who was the last

Re: [sqlite] integer primary key autoincrement & sqlite_sequence

2009-06-22 Thread João Eiras
On , Pavel Ivanov wrote: > Hi, Richard! > > Could you explain why this scenario doesn't cause infinite call cycle > of the trigger by itself? Is there some protection in SQLite which > breaks such cycles? > Many dbms forbid recursive trigger calls that modify a table that

Re: [sqlite] integer primary key autoincrement & sqlite_sequence

2009-06-22 Thread Oliver Peters
Am Montag, den 22.06.2009, 17:39 -0600 schrieb Dennis Cote: > Oliver Peters wrote: > > sorry: my code wasn't completely what I wanted so here again: > > > > CREATE TRIGGER IF NOT EXISTS test > > BEFORE INSERT ON "a" > > BEGIN > > INSERT INTO

Re: [sqlite] integer primary key autoincrement & sqlite_sequence

2009-06-22 Thread Dennis Cote
Oliver Peters wrote: > sorry: my code wasn't completely what I wanted so here again: > > CREATE TRIGGER IF NOT EXISTS test > BEFORE INSERT ON "a" > BEGIN > INSERT INTO a(code,name,creator) > VALUES(new."code",new."name",new."identity"); >

Re: [sqlite] integer primary key autoincrement & sqlite_sequence

2009-06-22 Thread Pavel Ivanov
Hi, Richard! Could you explain why this scenario doesn't cause infinite call cycle of the trigger by itself? Is there some protection in SQLite which breaks such cycles? Pavel On Mon, Jun 22, 2009 at 4:10 PM, D. Richard Hipp wrote: > > On Jun 22, 2009, at 3:33 PM, Oliver Peters

Re: [sqlite] integer primary key autoincrement & sqlite_sequence

2009-06-22 Thread D. Richard Hipp
On Jun 22, 2009, at 3:33 PM, Oliver Peters wrote: > Hello out there, > > > to my mind I get false entries in sqlite_sequence using this code: > > > CREATE TABLE IF NOT EXISTS a( > id INTEGER PRIMARY KEY AUTOINCREMENT, > code

Re: [sqlite] integer primary key autoincrement & sqlite_sequence

2009-06-22 Thread Oliver Peters
[...] > > The ROWID is not generated until the INSERT statement actually runs. > Hence the BEFORE trigger does not have access to it and the BEFORE > trigger sees a NULL. Change the trigger to an AFTER trigger and it > will work. > [...] > > D. Richard Hipp > d...@hwaci.com Thanks for

Re: [sqlite] integer primary key autoincrement & sqlite_sequence

2009-06-22 Thread D. Richard Hipp
On Jun 22, 2009, at 3:33 PM, Oliver Peters wrote: > Hello out there, > > > to my mind I get false entries in sqlite_sequence using this code: > > > CREATE TABLE IF NOT EXISTS a( > id INTEGER PRIMARY KEY AUTOINCREMENT, > code

[sqlite] integer primary key autoincrement & sqlite_sequence

2009-06-22 Thread Oliver Peters
Hello out there, to my mind I get false entries in sqlite_sequence using this code: CREATE TABLE IF NOT EXISTS a( id INTEGER PRIMARY KEY AUTOINCREMENT, codeVARCHAR NOT NULL, name

Re: [sqlite] INTEGER PRIMARY KEY and triggers

2008-11-17 Thread Hugh Gibson
> I am addicted to using INTEGER PRIMARY KEY AUTOINCREMENT as the id > fields in my SQLite projects, yet I would like to try some triggers > as well. Of course, every time I add a trigger that accesses a > table with these types of id fields, all sorts of odd things > happen. Not to

Re: [sqlite] INTEGER PRIMARY KEY and Triggers

2008-11-16 Thread Craig Smith
On Nov 17, 2008, at 12:45 AM, [EMAIL PROTECTED] wrote: >> I am addicted to using INTEGER PRIMARY KEY AUTOINCREMENT as the id >> fields in my SQLite projects, yet I would like to try some triggers >> as >> well. Of course, every time I add a trigger that accesses a table >> with these types

Re: [sqlite] INTEGER PRIMARY KEY and triggers

2008-11-16 Thread Dan
On Nov 16, 2008, at 2:46 AM, Craig Smith wrote: > I am addicted to using INTEGER PRIMARY KEY AUTOINCREMENT as the id > fields in my SQLite projects, yet I would like to try some triggers as > well. Of course, every time I add a trigger that accesses a table > with these types of id fields, all

[sqlite] INTEGER PRIMARY KEY and triggers

2008-11-15 Thread Craig Smith
I am addicted to using INTEGER PRIMARY KEY AUTOINCREMENT as the id fields in my SQLite projects, yet I would like to try some triggers as well. Of course, every time I add a trigger that accesses a table with these types of id fields, all sorts of odd things happen. I read in the

Re: [sqlite] integer primary key and unique index?

2008-04-15 Thread Dennis Cote
Petite Abeille wrote: > > Would adding an unique index on an integer primary key be of any > benefit? Or is it redundant? > It would not help, and would in fact slow down all inserts, deletes, and updates for no benefit. It is redundant. HTH Dennis Cote

[sqlite] integer primary key and unique index?

2008-04-15 Thread Petite Abeille
Hello, Would adding an unique index on an integer primary key be of any benefit? Or is it redundant? In "Primary key and index", Ben Carlyle wrote the following: 1 Table = 1 BTree, the BTree holds the data and is ordered by ROWID 1 Table with 1 Index = 2 BTrees, the second referring to rows

RE: [sqlite] INTEGER PRIMARY KEY Auto Increment Rollover Question

2007-10-16 Thread Odekirk, Shawn
>> Brickl Roland [mailto:[EMAIL PROTECTED] wrote: >> Integer PrimaryKeys are always autoincrementing. When you don't >> specify it it uses after (2^63)-1 a random free positiv value. >> "Odekirk, Shawn" <[EMAIL PROTECTED]> wrote: >> I will compile this for Windows and see what my results are

RE: [sqlite] INTEGER PRIMARY KEY Auto Increment Rollover Question

2007-10-15 Thread Odekirk, Shawn
Brickl Roland [mailto:[EMAIL PROTECTED] wrote: > Integer PrimaryKeys are always autoincrementing. When you don't > specify it it uses after (2^63)-1 a random free positiv value. "Odekirk, Shawn" <[EMAIL PROTECTED]> wrote: > I will compile this for Windows and see what my results are using a >

Re: [sqlite] INTEGER PRIMARY KEY Auto Increment Rollover Question

2007-10-15 Thread drh
"Odekirk, Shawn" <[EMAIL PROTECTED]> wrote: > My compiler is old and I don't think it supports a 64 bit data type. > Maybe this is the root cause of my problem. > Very likely. -- D. Richard Hipp <[EMAIL PROTECTED]>

RE: [sqlite] INTEGER PRIMARY KEY Auto Increment Rollover Question

2007-10-15 Thread Odekirk, Shawn
ubject: RE: [sqlite] INTEGER PRIMARY KEY Auto Increment Rollover Question Hallo Odekirk Shawn, SQLite use up to an 64Bit signed Integer for Primary Keys, even on non 64Bit-Systems! Integer PrimaryKeys are always autoincrementing. When you don't specify it it uses after (2^63)-1 a random free positiv value

RE: [sqlite] INTEGER PRIMARY KEY Auto Increment Rollover Question

2007-10-13 Thread Brickl Roland
Hallo Odekirk Shawn, SQLite use up to an 64Bit signed Integer for Primary Keys, even on non 64Bit-Systems! Integer PrimaryKeys are always autoincrementing. When you don't specify it it uses after (2^63)-1 a random free positiv value. When you write autoincrement for your create table it never

[sqlite] INTEGER PRIMARY KEY Auto Increment Rollover Question

2007-10-12 Thread Odekirk, Shawn
I am evaluating SQLite for a project I am working on. I have a question about the behavior of the INTEGER PRIMARY KEY auto increment feature. My platform uses 32 bit integers, so the valid values for an unsigned integer are 0 - 4294967296 and the valid values for a signed integer are -2147483648

[sqlite] INTEGER PRIMARY KEY

2007-02-12 Thread Tom Shaw
Here's a question on INTEGER PRIMARY KEY. I would like use IP addresses (converted to an unsigned number to man them monotonically increasing) for INTEGER PRIMARY KEY however I can't determine from the online docs whether if I supply an unsigned integer in PHP 5: $uip = sprintf("%u",

[sqlite] integer primary key initial value

2004-01-23 Thread Michael Hunley
This may be a totally rooky question, but better safe than sorry If I declare a table with an INTEGER PRIMARY KEY field s.t. it is an auto-increment, do the first INSERT into it and call sqlite_last_insert_rowid(), will I get back a 0 or something else? Will I ever get 0 back (in case it