[R] sqlite create new unique id

Chris Campbell ccampbell at mango-solutions.com
Tue Feb 21 11:14:13 CET 2012


Hi Alok

Are you certain that you are keeping your connection open? last_insert_rowid() returns id of last inserted row from the current database connection (which invoked the function). Is it possible that every time you run the query you making a new connection?

Hope this helps,
  
Chris Campbell
MANGO SOLUTIONS
Data Analysis that Delivers
+44 1249 767700

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Alok Jadhav
Sent: 21 February 2012 06:59
To: r-help at r-project.org
Subject: [R] sqlite create new unique id

Hi everyone,

 I am trying to insert a row in sqlite table with my own unique id. I want to create unique id using sqlite internal function
last_insert_rowid()  which returns the next max rowid of the table which is always unique. I tested this using sqlite and it works fine but when i run the same query using RSQlite from r prompt, my query doesn't create new unique id. 
last_insert_rowid()  always returns 0 value from RSQLite always returns 0.
How can I get a unique id using RSQLite ? 

my query looks like this
 "insert into PrimaryIdTable values ('AMP AT Equity','bbg','2001-01-01','2099-01-01','P'||last_insert_rowid())"

reason i am not using INTEGER PRIMARY KEY  is because i want to keep my key as TEXT datatype. This is because another table has same field for secondary id and both these keys appear in same table so i want to call them primary key (P1, P2 ) or secondary key (S1, S2 etc) . 

Thanks for your help,

Alok


--
View this message in context: http://r.789695.n4.nabble.com/sqlite-create-new-unique-id-tp4406114p4406114.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
LEGAL NOTICE
This message is intended for the use o...{{dropped:10}}



More information about the R-help mailing list