On Mon, Mar 16, 2009 at 8:59 AM, John Machin <[email protected]> wrote:
> On 17/03/2009 12:33 AM, P Kishor wrote:
>> On Mon, Mar 16, 2009 at 8:31 AM, P Kishor <[email protected]> wrote:
>>> is there a way to have a table start the INTEGER PRIMARY KEY sequence
>>> at 0 (or some other arbitrary number)?
>>>
>>> --
>>> Puneet Kishor
>>>
>>
>> I should have added.. yes, I can do the following
>>
>> CREATE TABLE foo (a INTEGER PRIMARY KEY, b TEXT);
>> INSERT INTO foo VALUES (0, 'blah');
>>
>> but, I want to do
>>
>> INSERT INTO foo (b) VALUES ('blah');
>>
>> additionally, are their any gotchas with forcing INTEGER PRIMARY KEY
>> (hence, the ROWID) to start from 0?
>>
>>
> Hi Puneet,
>
> Have you read this: http://www.sqlite.org/autoinc.html ? The first part
> appears to cover non-autoincrement as a background to explaining the
> subtle differences with auto increment.
right... read that.
>
> It appears that you will need to write the first ROWID explicitly.
> There may be a gotcha with zero, otherwise why pick 1 for the default?
dunno... only DRH can tell, but it just may be convention. My modeling
program uses 0 as the first index, and arrays in C and Perl start at 0
as well. But SQLite implements 'stuff' starting at base 1. For
example, consider
sqlite> SELECT substr('blah', 1, 1);
b
sqlite> SELECT substr('blah', 0, 1);
sqlite>
> What are you trying to achieve? If you are going to let the software
> choose your PK for you, why do you care what the starting value is?
compatibility. And, as 'they' say, 0 is a perfectly fine number. Why
let it go waste.
>
> Cheers,
> John
--
Puneet Kishor http://www.punkish.org/
Nelson Institute for Environmental Studies http://www.nelson.wisc.edu/
Carbon Model http://carbonmodel.org/
Open Source Geospatial Foundation http://www.osgeo.org/
Sent from: Madison WI United States.
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users