![]() So, if PostgreSQL can guarantee that no two insert/update operations will occur at the same timestamp, then I could use it as a primary key, BUT if not then obviously I cannot use this solution. ![]() You know the purpose of the primary key is to determine each row in the table uniquely. A table with no primary key columns can have only one row. ![]() A key based off of contextual data at the present time, may not have the same contextual meaning later. In the database I have some table where no primary key is applicable except time (Audit trail), and specifying a sequence (hibernate_sequence) increases the number to an extremely high degree which makes it inconvenient to work with other tables as it affects all tables with sequence as primary key. PostgreSQL has data types SERIAL and BIGSERIAL that are used for the auto-increment purpose, which means you can define the column data type as SERIAL and BIGSERIAL, and the primary key for that column is added automatically. If you want to update or delete existing rows in a table, then the table must have a primary key. The primary key must stand the test of time. Are there any approaches like this that are used in practise that work with any database? That would be good to know.ĮDIT : What I am asking is that since no two moments of time are the same for us (humans), does that also hold true for computers? I know that the computers track time through the vibration of some crystal (not sure how small a time it can measure). You define primary keys through primary key constraints. For Auto Increment Integer, when stored as Long format, it occupies 8 bytes. A primary key is a column or a group of columns used to identify a row uniquely in a table. Thinking of issue id, obviously, issue-123 is much more readable than issue-b1e92c3b-a44a-4856-9fe3-925444ac4c23. 1 Answer Sorted by: 13 Quote from the manual Adding a primary key will automatically create a unique B-tree index on the column or group of columns listed in the primary key, and will force the column (s) to be marked NOT NULL. This is especially valuable if we would expose it externally. I am working on a database with huge hibernate sequences in the keys, so I thought of using timestamps as a solution. PostgreSQL - SERIAL SQLite - AUTOINCREMENT Readable. A table can have one and only one primary key. Technically, a primary key constraint is the combination of a not-null constraintand a UNIQUE constraint. ![]() Couldn't we use timestamps instead of integers for this purpose? Is there any flaw in that strategy, because I assume that the machine cannot do two things at the same "time".right? A primary key is a column or a group of columns used to identify a row uniquely in a table. The majority of times we use integer sequences for primary keys to maintain uniqueness of row in a table. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |