![]() 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. The user must have REFERENCES permission on the referenced table (either the whole table, or the specific referenced columns). The referenced columns must be the columns of a non-deferrable unique or primary key constraint in the referenced table. 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. If the refcolumn list is omitted, the primary key of the reftable is used. 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). ![]() I am working on a database with huge hibernate sequences in the keys, so I thought of using timestamps as a solution. 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. You define primary keys through primary key constraints. 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. By assigning a SERIAL type to a column during table creation, PostgreSQL creates a sequence using the default configuration and adds a NOT NULL constraint to. In the database I have some table where no primary key is applicable except time (Audit trail), and specifying a sequence (hibernatesequence) 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. ![]() As indicated in the official documentation, SERIAL is not a true data type, but is simply shorthand notation that tells Postgres to create a auto incremented, unique identifier for the. with nextval: always safe, but the the generated value won't be in sync with the primary key. ![]() The majority of times we use integer sequences for primary keys to maintain uniqueness of row in a table. By far the simplest and most common technique for adding a primary key in Postgres is by using the SERIAL or BIGSERIAL data types when CREATING a new table. - with currval: as long as you use the DEFAULT for your primary key (or omit it in the INSERT ), or use nextval (.) directly at insertion for this primary key, it is safe. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |