Rich Shepard <rshep...@appl-ecosys.com> wrote:
> On Thu, 22 Oct 2009, Simon Slavin wrote:
> 
>> I'm using a TRIGGER that is triggered AFTER INSERT.  The INSERT
>> commands do not know or set the value for the ROWID column.  Can I
>> reliably fetch the value for this column from 'NEW.' ?  Or can I
>> rely only on values which are explicitly set in the INSERT command ?
> 
>   I cannot directly answer your question because I have always
> avoided using the rowid for _anything_. There's no guarantee that a
> given row will always have the same position in the set, so all the
> SQL experts I've read advise against using it. Can you assign a
> unique identifier to each row as the primary key? If so, use that in
> the trigger. 

In SQLite, ROWID _is_ the unique identifier for each record. Any field declared 
INTEGER PRIMARY KEY is simply an alias for ROWID. "Position in the set", 
whatever it is, has nothing to do with it.

To Simon: yes, in my experience, AFTER INSERT trigger can happily access 
new.ROWID and/or new.YourId (where YourId is your own column declared INTEGER 
PRIMARY KEY and thus serving as an alias for ROWID). However, not being a 
SQLite developer, I can't give any kind of official guarantee. Hopefully 
someone important will chime in.

Igor Tandetnik

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to