I am creating table like this:
CREATE TABLE foobar (id uniqueidentifier, foo text, bar text, PRIMARY KEY (id))
How to insert or generate value for id field in table foobar?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can argue that SQLite doesn’t support data types at all. In SQLite3, you can do this, for example.
SQLite will happily create a column with the “data type” wibblewibble. SQLite will also happily create columns with the “data types” uuid, guid, and SuperChicken.
The crucial point for you is probably how to automatically generate a uid. SQLite can’t help you much there.
You can leave it entirely up to the client program. If you’re programming in python, use the uuid module. In ruby, you have the SecureRandom.uuid function. Other languages have similar features or workarounds.
You can write your own uid-generating function in C. (See Create or Redefine SQL Functions.) I’d call this a relatively extreme approach.
You can store it in either binary or text format.
Other conversations online suggest that there’s a widespread misunderstanding about what a UUID is. A UUID is not simply a 128-bit random number. A UUID has structure and rules. See RFC 4122.