N
N
nakem2022-03-18 00:23:14
PostgreSQL
nakem, 2022-03-18 00:23:14

Where is the best place to generate a uuid for a base? In code or in sql query?

Well, the whole question is in the title. You need to generate uuid for primary keys. It is better to generate in the code or in the request by the function.
In general, one gets the feeling that there is no difference, but still decided to clarify.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
entermix, 2022-03-18
@entermix

In code, because it's easier to unit test or bind entities

S
Sergey Tomulevich, 2022-03-18
@phoinixrw

By and large, it doesn't matter.
But it strongly depends on how the UUID is generated on the client.
For example, when using rand based on time, I encountered a uniqueness problem when inserting records densely into the database (with a record density of more than 10K per sec, this error will manifest itself stably).

N
nApoBo3, 2022-03-18
@nApoBo3

On the client. This is probably the main reason why to use uuid. You can generate it not centrally.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question