N
N
nepster-web2017-02-07 13:20:31
PostgreSQL
nepster-web, 2017-02-07 13:20:31

Should I use uuid or is there something else?

Often there is a task when it is necessary to "complete" an object and especially to know its identifier before it flies to the database.
This can be achieved using uuid, but there are much more minuses than pluses:
- Performance drops when selecting and inserting
- Performance drops when JOIN
- The base grows
Therefore, the question is:
How can an id for an object be generated earlier without much harm to the base?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry MiksIr, 2017-02-07
@miksir

> How without special harm to basis it is possible to generate id for object for earlier?
SELECT nextval('name_of_sequence');

L
lega, 2017-02-07
@lega

Options:
1) Generated unique id (guid)
2) Numerator, you need to store a global counter somewhere, redis / db
3) Prefixes / suffixes, each writer has his own prefix and enumerator, for example
Writer 1: 10001, 10002, 10003 .. Writer 2 :
20001, 20002, 20003...
Writer 3: 30001, 30002, 30003...
Either modulo, writer 1 only writes odd numbers, writer 2 only writes even numbers

F
Falseclock, 2017-02-16
@Falseclock

Why know in advance? I don't imagine it.
If, after adding a new line to the database, you want to know the unique ID generated in the database, then do this

INSERT INTO table_name (column1,column2) VALUES (value1,value2) RETURNING table_column_id;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question